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

Re: How to sort a $variable and store that into anothe

Subject: Re: How to sort a $variable and store that into another $variable ?
From: Martin Honnen <Martin.Honnen@xxxxxx>
Date: Wed, 10 Dec 2008 19:30:55 +0100
Re:  How to sort a $variable and store that into anothe
Jean-Philippe Martin wrote:

I'm trying to sort a <xsl:variable> containing 22 nodes and store this
sorted list into another xsl:variable.

Is this possible ?


Is there a way to do this ?

Ps: this is xsl 1.0.

There is a way if you show us your XML input and how exactly you initialize your first variable.


Assuming the XML input document is

<root>
  <foo>10</foo>
  <foo>2</foo>
  <foo>1</foo>
  <foo>4</foo>
</root>

then this stylesheet

<xsl:stylesheet
  version="1.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:output indent="yes"/>

  <xsl:template match="/">
    <xsl:variable name="v1" select="root/foo"/>
    <xsl:variable name="v2">
      <xsl:for-each select="$v1">
        <xsl:sort select="." data-type="number"/>
        <xsl:copy-of select="."/>
      </xsl:for-each>
    </xsl:variable>
    <result>
      <xsl:copy-of select="$v2"/>
    </result>
  </xsl:template>

</xsl:stylesheet>

outputs

<result>
   <foo>1</foo>
   <foo>2</foo>
   <foo>4</foo>
   <foo>10</foo>
</result>

Variable v1 has the foo elements from the XML input, variable v2 a result tree fragment of the sorted foo elements.

--

	Martin Honnen
	http://JavaScript.FAQTs.com/

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.