tags:

views:

115

answers:

2

Take this XSL:

  <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"/>

I get the output as

No. of Rows: - 10

Now how to write a loop in xsl to traverse each row till the 10th row?

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?

+3  A: 

You use a selector over the rows and a foreach: http://www.w3schools.com/Xsl/xsl%5Ffor%5Feach.asp. You can keep it under the 10th row by using a qualifier like [position() < 10].

Jeff Ober
+1  A: 

Use this XPath expression: .../DBE:TableRow[position()<10]

Aaron Digulla
I tried the below:-[code]<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 -->[xsl:for-each select="../DBE:Object[@Class='A']/DBE:Attribute[@name='B']/DBE:Table/DBE:TableRow[position() < $rowcount>display some attributes</xsl:for-each>How the counter or position will get incremented and i can display all the rows correctly?
prashant rao
`position()` is the position of the element, so it changes with every element that for-each considers.
Aaron Digulla