[xsl] Difficulty over understanding preceding-sibling

Subject: [xsl] Difficulty over understanding preceding-sibling
From: "Joe Fawcett" <joefawcett@xxxxxxxxxxx>
Date: Sat, 3 Sep 2005 00:48:50 +0100
Can anyone explain why the first item being passed to the template has any preceding-sibling?
<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" />

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>
 <xsl:param name="groupSize" select="3" />
 <xsl:template match="/">
     <xsl:call-template name="groupItems">
       <xsl:with-param name="items" select="root/item" />

<xsl:template name="groupItems">
<xsl:param name="items" />
<xsl:variable name="itemCount" select="count($items)" />
<xsl:if test="$itemCount &gt; 0">
<xsl:for-each select="$items">
<xsl:if test="position() &lt;= $groupSize">
<newItem id="{@id}">
<xsl:if test="position() = 1">
<xsl:attribute name="preceding-sibling-count">
<xsl:value-of select="count(preceding-sibling::item)" />
<xsl:call-template name="groupItems">
<xsl:with-param name="items" select="$items[position() &gt; $groupSize]" />

Result (msxml version 4):
<group itemCount="10">
 <newItem id="1" preceding-sibling-count="0"/>
 <newItem id="2"/>
 <newItem id="3"/>
<group itemCount="7">
 <newItem id="4" preceding-sibling-count="3"/>
 <newItem id="5"/>
 <newItem id="6"/>
<group itemCount="4">
 <newItem id="7" preceding-sibling-count="6"/>
 <newItem id="8"/>
 <newItem id="9"/>
<group itemCount="1">
 <newItem id="10" preceding-sibling-count="9"/>

Why doesn't the preceding-sibling-count show zero, or am I just up too late?



Current Thread