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

Re: Putting a nodeset in a variable

Subject: Re: Putting a nodeset in a variable
From: Joerg Heinicke <joerg.heinicke@xxxxxx>
Date: Sun, 24 Nov 2002 00:02:49 +0000
xslt nodeset
Hello Ismael,

the template

<xsl:template match="/">
  <xsl:for-each select="traps/trap">
    <xsl:sort select="./@id"/>
    <xsl:value-of select="@id"/>
  </xsl:for-each>
</xsl:template>

does the same like your one. But you called your variable distinctValues, so I assume you *want* distinct values. Then it is a grouping problem and the most propagated method is the Muenchian one:

<xsl:key name="traps" match="trap" use="@id"/>

<xsl:template match="/traps">
  <xsl:for-each select="trap[generate-id() =
                                    generate-id(key('traps', @id))]">
    <xsl:sort select="@id"/>
    <xsl:value-of select="@id"/>
  </xsl:for-each>
</xsl:template>

And the most propagated web resource relating to Muenchian Method is http://www.jenitennison.com/xslt/grouping/muenchian.xml.

Regards,

Joerg

Cams Ismael wrote:
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


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.