Subject: Re: [xsl] How to iterate over the output of distinct-values()? From: "Dimitre Novatchev" <dnovatchev@xxxxxxxxx> Date: Tue, 6 Jun 2006 10:29:51 -0700 |
In addition to the detailed explanation provided by Dr. Kay, the problem probably could be avoided altogether had the <xsl:for-each-group> instruction been used.
I'd also recommend to use a reference to an xsl:function over using xsl:call-template
-- Cheers, Dimitre Novatchev --------------------------------------- Truly great madness cannot be achieved without significant intelligence.
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 |
---|
|
<- Previous | Index | Next -> |
---|---|---|
RE: [xsl] How to iterate over the o, Michael Kay | Thread | [xsl] [ANN] oXygen XML editor 7.2, George Cristian Bina |
RE: [xsl] How to iterate over the o, Michael Kay | Date | [xsl] Inserting Entities into an XM, Chad Chelius |
Month |