xsl-list
[Top] [All Lists]

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

2006-06-06 10:09:38
Within the execution of

<xsl:for-each select="distinct-values(...)">

the context item is an atomic value.

When you do count(/ROWSET/ROW[CONTRACTOR='$contractor']), the meaning of the
initial "/" is "find the root of the tree containing the context node". But
there isn't a context node (the context item is an atomic value). You need
to pass the template a parameter telling it what document to look in, and
use an expression such as count($input/ROWSET/ROW[CONTRACTOR=$contractor]).

The reason you're getting 0 is that '$contractor' shouldn't be in quotes.

Michael Kay
http://www.saxonica.com/


-----Original Message-----
From: cknell(_at_)onebox(_dot_)com [mailto:cknell(_at_)onebox(_dot_)com] 
Sent: 06 June 2006 17:56
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: [xsl] How to iterate over the output of distinct-values()?

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='$con
tractor'])

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(_at_)onebox(_dot_)com - email

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: 
<mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--



--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

<Prev in Thread] Current Thread [Next in Thread>