lclqt12 Posted November 24, 2010 Share Posted November 24, 2010 Hi all,I have two nested loop in XSL like this, at this moment I use position() but it's not what I need. <xsl:for-each select="abc"> <xsl:for-each select="def"> I wanna my variable in here increasing fluently 1,2,3,4,5.....n not like 1,2,3,1,2,3 </xsl:for-each> </xsl:for-each> do you have anyways to do it ? Link to comment Share on other sites More sharing options...
Martin Honnen Posted November 24, 2010 Share Posted November 24, 2010 Why can't you simply do <xsl:for-each select="abc/def">...</xsl:for-each> ? That way position() should give you what you are looking for. Link to comment Share on other sites More sharing options...
lclqt12 Posted November 24, 2010 Author Share Posted November 24, 2010 Why can't you simply do<xsl:for-each select="abc/def">...</xsl:for-each> ? That way position() should give you what you are looking for. if i have a xml file like : <root> <abc name="John"> <def>A</def> <def>B</def> </abc> <abc name="Matthew"> <def>C</def> <def>D</def> <def>E</def> </abc> <abc name="Berry"> <def>F</def> </abc></root> and i want it to display like this : 1. John A2. John B--------------------------------------3. Matthew C4. Matthew D5. Matthew E--------------------------------------6. Berry F Therefore, i could not run only 1 foreach loop. I want to get index of <def> node in root NOT index in abc node.Ex : + <def>D</def> must has index is 4 ( instead of 2 )+ <def>F</def> must has index is 6 ( instead of 1 ) Link to comment Share on other sites More sharing options...
Martin Honnen Posted November 24, 2010 Share Posted November 24, 2010 Use xsl:number: <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"><xsl:strip-space elements="*"/><xsl:output method="text"/><xsl:template match="abc/def"> <xsl:number level="any" format="1."/> <xsl:value-of select="concat(' ', parent::abc/@name, ' ', ., '')"/> <xsl:if test="position() = last()"> <xsl:text>---------------</xsl:text> </xsl:if></xsl:template></xsl:stylesheet> output with Saxon 6.5.5 is 1. John A2. John B---------------3. Matthew C4. Matthew D5. Matthew E---------------6. Berry F--------------- Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.