Connecting Tech Pros Worldwide Forums | Help | Site Map

xsl:how to traverse through a loop and increment the counter each time for all rows

Newbie
 
Join Date: Sep 2009
Posts: 18
#1: Oct 7 '09
I tried the below:-
Expand|Select|Wrap|Line Numbers
  1. <xsl:variable name="rowcount" select="count(../DBE:Object[@Class='A']/DBE:Attribute[@name='B']/DBE:Table/DBE:TableRow)"/> 
No. of Rows: - <xsl:value-of select="$rowcount"/>

Now i used -->
Expand|Select|Wrap|Line Numbers
  1. <xsl:for-each select="../DBE:Object[@Class='A']/DBE:Attribute[@name='B']/DBE:Table/DBE:TableRow[position() &lt; $rowcount">
  2. display some attributes
  3. </xsl:for-each>
How the counter or position will get incremented and i can display all the rows correctly?

Dormilich's Avatar
Moderator
 
Join Date: Aug 2008
Location: Leipzig, Germany
Posts: 3,650
#2: Oct 7 '09

re: xsl:how to traverse through a loop and increment the counter each time for all rows


Quote:

Originally Posted by prao2005 View Post

How the counter or position will get incremented and i can display all the rows correctly?

I didn’t understand, can you elaborate that?
Newbie
 
Join Date: Sep 2009
Posts: 18
#3: Oct 7 '09

re: xsl:how to traverse through a loop and increment the counter each time for all rows


Quote:

Originally Posted by Dormilich View Post

I didn’t understand, can you elaborate that?

--> [My answer]
I want to display all the rows of a table till the end of table is encountered.

So, in a way need to traverse through the loop and display first row and then automatically position() or counter should be incremented and then display the second row in the second line and so on....

Suppose no. of rows in a table = 10
Header --> A B C
row1 --> 10 abc 20
row2 --> 20 def 10
....
....
row10 --> 30 xyz 40

Please let me know how to achieve the above output?
Dormilich's Avatar
Moderator
 
Join Date: Aug 2008
Location: Leipzig, Germany
Posts: 3,650
#4: Oct 7 '09

re: xsl:how to traverse through a loop and increment the counter each time for all rows


something like
Expand|Select|Wrap|Line Numbers
  1. <xsl:for-each select="…/DBE:TableRow">
  2. // cell 1
  3. <xsl:text>row</xsl:text>
  4. <xsl:value-of select="position()"/>
  5. // other cells
  6. </xsl:for-each>
Newbie
 
Join Date: Sep 2009
Posts: 18
#5: Oct 7 '09

re: xsl:how to traverse through a loop and increment the counter each time for all rows


Quote:

Originally Posted by Dormilich View Post

something like

Expand|Select|Wrap|Line Numbers
  1. <xsl:for-each select="…/DBE:TableRow">
  2. // cell 1
  3. <xsl:text>row</xsl:text>
  4. <xsl:value-of select="position()"/>
  5. // other cells
  6. </xsl:for-each>

-->
I tried the below
Expand|Select|Wrap|Line Numbers
  1. <xsl:for-each select="../DBE:Object[@Class='A']/DBE:Attribute[@name='B']/DBE:Table/DBE:TableRow">
  2. <xsl:value-of select="DBE:Attribute[@name='B']/DBE:Table/DBE:TableRow[position()]/DBE:TableData[1]"/>
  3. </xsl:for-each>
Now i do not getting any values displayed....
Dormilich's Avatar
Moderator
 
Join Date: Aug 2008
Location: Leipzig, Germany
Posts: 3,650
#6: Oct 7 '09

re: xsl:how to traverse through a loop and increment the counter each time for all rows


Quote:

Originally Posted by prao2005 View Post

Now i do not getting any values displayed....

of course. I doubt that DBE:Attribute is a child of DBE:TableRow.
Newbie
 
Join Date: Sep 2009
Posts: 18
#7: Oct 7 '09

re: xsl:how to traverse through a loop and increment the counter each time for all rows


Quote:

Originally Posted by Dormilich View Post

of course. I doubt that DBE:Attribute is a child of DBE:TableRow.


Yes, you are right. The first and the third columns are children of DBE:TableRow while the second column is DBE:Attribute. (in below table)

Header --> A B C
row1 --> 10 abc 20
row2 --> 20 def 10


So, is there any way that i initialize n=1 then traverse a loop until the total count of rows in the table and display the values -->
Reply