[XSL-LIST Mailing List Archive Home]
[By Thread]
[By Date]
[xsl] counting with position()
Subject: [xsl] counting with position() From: a kusa <akusa8@xxxxxxxxx> Date: Tue, 5 Jan 2010 13:39:09 -0600 |
Hi I am trying to count nodes after a certain node and am having difficulties with it. Here is my snippet: <level1> <item>Sample</item> <level2> <item>Sample</item> <product>sample prod1</product> <product>sample prod2</product> <product>sample prod3</product> <level3> <item>Sample</item> <item>Sample</item> </level3> </level2> <level1> So I am trying to count all 'product elements after <item> in the template level2. Here is a part of my xslt. <xsl:template match="level2"> <xsl:if test="following-sibling::*[1][self::product[preceding-sibling::*[1][self::ite m] and following-sibling::*[self::product[(position()=last()) and not(string(following-sibling::*[1]))]]]]"> <xsl:variable name="count" select="count(./following-sibling::product[position()!=last()])"/> <xsl:if test="$count>= 1"> <xsl:apply-templates select="./following-sibling::product[position() < $count]"/> </xsl:if> </xsl:if> </xsl:template> I am trying to find out if there is more than one 'product' after <item> and if that occurs at the end of <item> just before <level3> starts. The transformation is a lot more complicated than just this, since these are all nested levels and this kind of structure can occur in an another <level3> element down the node tree. After I check that, I count the product elements and transform them. But when I use ./following-sibling::product[position() < $count], it only shows 1 product element. How do I count all the product elements and display until the last one?
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
RE: [xsl] Retrieving sequence of un, Robby Pelssers | Thread | Re: [xsl] counting with position(), Syd Bauman |
Re: [xsl] Retrieving sequence of un, G. Ken Holman | Date | Re: [xsl] Associating javascript wi, Wendell Piez |
Month |