[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: Hello - how do I use the count function properly?
And on every 4th subcategory I just want to set the margin- right: 0px. There are several significant problems with this code. First, xsl:for-each sets the context node, and any path expression immediately within the for-each selects using that context node as its start point. If you wrote "child::category" or "./child::category", you would be testing whether the category node you are currently processing has 4 (or 8) children called category, whereas you actually want to test whether it has 3 (or 7) preceding siblings called category. Secondly, by writing /child:category, you are not selecting children of the context node, but children of the root (document) node at the top of the tree. (A document node in a well-formed XML document has exactly one element child, so testing whether it has 4 or 8 children will always return false.) You could write this as <xsl:for-each select="child::category"> <xsl:choose> <xsl:when test="count(preceding-sibling::category) = 3 or count(preceding-sibling::category) = 7" but I would tend to write it as <xsl:for-each select="child::category"> <xsl:choose> <xsl:when test="position() mod 4 = 0" ... The position() function returns 1, 2, 3, ,,, in successive executions of the xsl:for-each body. Michael Kay Saxonica
|
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
|