[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

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

Subject: How to iterate over the output of distinct-values()?
From: cknell@xxxxxxxxxx
Date: Tue, 06 Jun 2006 12:55:49 -0400
xpty0020
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

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.