[xsl] How to iterate over the output of distinct-values()?

Subject: [xsl] How to iterate over the output of distinct-values()?
From: cknell@xxxxxxxxxx
Date: Tue, 06 Jun 2006 12:55:49 -0400
I have a document that consists of elements like this.

 <ROW>
  <CONTRACTOR></CONTRACTOR>
  <CASE_NO></CASE_NO>
  <SCHD_DATE></SCHD_DATE>
  <VERBAL></VERBAL>
  <COMPLT></COMPLT>
  <DOE_DTE></DOE_DTE>
 </ROW>

While there are a few thousand rows, there are only a few distinct values for CONTRACTOR. I am working on a stylesheet that will perform various counts of data in these elements.

I thought I would get the distinct values for CONTRACTOR with the distinct-values() function and the supply each distinct value as a parameter to an xsl:call-template, like this:

<xsl:for-each select="distinct-values(ROWSET/ROW/CONTRACTOR)">
  <xsl:sort select="." />
  <xsl:call-template name="contractor-row">
     <xsl:with-param name="contractor" select="." />
  </xsl:call-template>
</xsl:for-each>

The context node where this is done is "/" and ROWSET in the root element.

When the xsl:call-template is executed, Saxon gives this error:

"XPTY0020: Finding root of tree: the context item is not a node"

Here is the relevant part of the called template:

<xsl:template name="contractor-row">
  <xsl:param name="contractor" />
  <tr height="17" style='height:12.75pt'>
    <td height="17" class="xl28" style='height:12.75pt;border-top:none'>
      <xsl:value-of select="$contractor" />
    </td>
    <td class="xl26" align="right" style='border-top:none;border-left:none' x:num="">
      <xsl:value-of select="count(/ROWSET/ROW[CONTRACTOR='$contractor'])" />
    </td>
 ... more template here ...
</xsl:template>

The processor emits this error message when evaluating 
count(/ROWSET/ROW[CONTRACTOR='$contractor'])

Now if I change the argument to the count() function to read:
count(document('path-to-xml-file')/ROWSET/ROW[CONTRACTOR='$contractor'])

The error goes away. It also returns a value of '0' (zero) for every call of the function.

Can anyone shed light on any part of this (to me, at least) puzzle?

Thanks.

-- 
Charles Knell
cknell@xxxxxxxxxx - email

Current Thread