[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Difficulty over understanding preceding-sibling
Can anyone explain why the first item being passed to the template has any
preceding-sibling?
XML: <root> <item id="1" /> <item id="2" /> <item id="3" /> <item id="4" /> <item id="5" /> <item id="6" /> <item id="7" /> <item id="8" /> <item id="9" /> <item id="10" /> </root> XSLT: <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:param name="groupSize" select="3" /> <xsl:template match="/"> <new> <xsl:call-template name="groupItems"> <xsl:with-param name="items" select="root/item" /> </xsl:call-template> </new> </xsl:template> <xsl:template name="groupItems"> <xsl:param name="items" /> <xsl:variable name="itemCount" select="count($items)" /> <xsl:if test="$itemCount > 0"> <group> <xsl:for-each select="$items"> <xsl:if test="position() <= $groupSize"> <newItem id="{@id}"> <xsl:if test="position() = 1"> <xsl:attribute name="preceding-sibling-count"> <xsl:value-of select="count(preceding-sibling::item)" /> </xsl:attribute> </xsl:if> </newItem> </xsl:if> </xsl:for-each> </group> <xsl:call-template name="groupItems"> <xsl:with-param name="items" select="$items[position() > $groupSize]" /> </xsl:call-template> </xsl:if> </xsl:template> </xsl:stylesheet> Result (msxml version 4): <new> <group itemCount="10"> <newItem id="1" preceding-sibling-count="0"/> <newItem id="2"/> <newItem id="3"/> </group> <group itemCount="7"> <newItem id="4" preceding-sibling-count="3"/> <newItem id="5"/> <newItem id="6"/> </group> <group itemCount="4"> <newItem id="7" preceding-sibling-count="6"/> <newItem id="8"/> <newItem id="9"/> </group> <group itemCount="1"> <newItem id="10" preceding-sibling-count="9"/> </group> </new> Why doesn't the preceding-sibling-count show zero, or am I just up too late? -- Joe
|
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
|