RE: [xsl] Putting a nodeset in a variable

Subject: RE: [xsl] Putting a nodeset in a variable
From: Cams Ismael <Ismael.Cams@xxxxxxxxxxxxxxx>
Date: Fri, 22 Nov 2002 14:52:36 +0100
Thanks for your help. However because I want to keep my stylesheet processor
independent it's not possible to use extensions. So I guess I have to look
for another solution.

Kind regards,
Ismaël

-----Original Message-----
From: Vasu Chakkera [mailto:vasucv@xxxxxxxxxxx]
Sent: vrijdag 22 november 2002 14:38
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: Re: [xsl] Putting a nodeset in a variable


><xsl:for-each select="$distinctValues/trap">
> Expression must evaluate to a node-set.

yes ..
You can not iterate through the variable that way. you must make use of the
nodeset extension of the form xxx:nodeset()..
example , for your problem, if you are using XALAN , then you may wish to do
the following ,

<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
xmlns:xalan="http://xml.apache.org/xalan"; extension-element-prefixes="xalan"
version="1.0">
<xsl:template match="/">
<xsl:variable name="distinctValues">
<traps>
<xsl:for-each select="traps/trap">
<xsl:sort select="./@id"/>
<xsl:copy-of select="."/>
</xsl:for-each>
</traps>
</xsl:variable>

<xsl:for-each select="xalan:nodeset($distinctValues)/traps/trap">
<xsl:value-of select="@id"/>
</xsl:for-each>
</xsl:template>

</xsl:stylesheet>
This should print 2556..

If however, you are using a different processor, you must check the
documentation to see how you can use the nodeset() extension function..
HTH


----- Original Message -----
From: "Cams Ismael" <Ismael.Cams@xxxxxxxxxxxxxxx>
To: <xsl-list@xxxxxxxxxxxxxxxxxxxxxx>
Sent: Friday, November 22, 2002 1:10 PM
Subject: [xsl] Putting a nodeset in a variable


> Hello,
>
> is it possible to put a nodeset in a variable.
> What I try to do is the following. I have an xml file which I want to
group.
> This resulting tree I want to put in a variable so I can use it later on.
>
> E.g.
> <traps>
> <trap id="5"/>
> <trap id="6"/>
> <trap id="2"/>
> <trap id="5"/>
> </traps>
>
> <xsl:variable name="distinctValues">
> <traps>
> <xsl:for-each select="traps/trap">
> <xsl:sort select="./@id"/>
> <xsl:copy-of select="."/>
> </xsl:for-each>
> </traps>
> </xsl:variable>
>
> <xsl:template match="/">
> <xsl:for-each select="$distinctValues/trap">
> <xsl:value-of select="@id"/>
> </xsl:for-each>
> </xsl:template>
>
> When I try to do this I get following error:
> Expression must evaluate to a node-set.
>
> Can somebody give me a hint if this is possible ?
>
> Kind regards,
> Ismaël
>
>
>
>
>  XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
>

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread