472,133 Members | 1,458 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,133 software developers and data experts.

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

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?
Oct 7 '09 #1
6 4534
Dormilich
8,658 Expert Mod 8TB
@prao2005
I didn’t understand, can you elaborate that?
Oct 7 '09 #2
@Dormilich
--> [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?
Oct 7 '09 #3
Dormilich
8,658 Expert Mod 8TB
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>
Oct 7 '09 #4
@Dormilich
-->
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....
Oct 7 '09 #5
Dormilich
8,658 Expert Mod 8TB
@prao2005
of course. I doubt that DBE:Attribute is a child of DBE:TableRow.
Oct 7 '09 #6
@Dormilich

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 -->
Oct 7 '09 #7

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

9 posts views Thread by Collin VanDyck | last post: by
2 posts views Thread by Tjerk Wolterink | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.