Hi,
The reason of misfunctionality of the line:
<xsl:value-of select="$CurrentEmployee" /> worked <xsl:value-of select="//Resources/ProjectRole/User/HiredWorkDays[preceding-sibling::UserName[1] = $CurrentEmployee]" /> days<br />
is the following(both Xalan and Saxon behave properly):
In the first recursive step the variable $CurrentEmployee has a nodeset as its value which contains 2 UserName nodes, since $EmployeePile is empty yet. So, xsl:value-of outputs the first node's value(as stated in XSLT's spec for xsl:value-of when 'select' attribute's value is a nodeset). And when you want to output the 'days' part(the equality predicate is tested), the processor takes all HiredWorkDays elements which are in your XML file, and here the equality operator makes the trick: you are comparing 2 nodesets; the first nodeset contains only the second UserName element(the path //Resources/ProjectRole/User/HiredWorkDays takes all HiredWorkDays elements in your XML, and hence in the predicate each one will became a context node, and preceding-sibling::UserName[1] will contain the second UserName element in document order) and the second nodeset is contained in $CurrentEmployee which is a set of all UserName nodes.
The equality predicate for nodeset operands returns true iff there is at least one pair of nodes from that 2 nodesets with matching string values! This holds in this case, since the second UserName element(in document order) is both in your left and right operands of the equality operator. That's why the stylesheet outputs "12 days" in the first step of the recursion.
I changed the template "WorkableHoursTotal", so it now works(other parts are the same). Here the position() function doesn't work, since the nodeset $SetOfEmployees contains nodes which are not siblings, that's why I use $NewPosition parameter.
<xsl:template name="WorkableHoursTotal">
<xsl:param name="CurrentMonth" select="1" />
<xsl:param name="SetOfEmployees" select="//Resources/ProjectRole/User/UserName[not(preceding::UserName = .)]" />
<xsl:param name="NewPosition" select="1"/>
<xsl:choose>
<xsl:when test="not($NewPosition > count($SetOfEmployees))">
<xsl:variable name="CurrentEmployee" select="$SetOfEmployees[$NewPosition]"/>
<xsl:value-of select="$CurrentEmployee" /> worked <xsl:value-of select="$CurrentEmployee/../HiredWorkDays" /> days<br />
<xsl:call-template name="WorkableHoursTotal">
<xsl:with-param name="CurrentMonth" select="$CurrentMonth" />
<xsl:with-param name="NewPosition" select="$NewPosition + 1"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
End of loop.
</xsl:otherwise>
</xsl:choose>
</xsl:template>
Regards,
Armen
|