counting with position()
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::*[self::product[preceding-sibling::*[self::ite m] and following-sibling::*[self::product[(position()=last()) and not(string(following-sibling::*))]]]]"> <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?
PURCHASE STYLUS STUDIO ONLINE TODAY!
Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!
Download The World's Best XML IDE!
Accelerate XML development with our award-winning XML IDE - Download a free trial today!
Subscribe in XML format