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

Re: Sort an xml file by the using the ordering/sorting

Subject: Re: Sort an xml file by the using the ordering/sorting information from another xml file
From: "Mukul Gandhi" <gandhi.mukul@xxxxxxxxx>
Date: Thu, 11 May 2006 14:06:18 +0530
xsl sort with other file
Please try this

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:output method="xml" indent="yes" />

<xsl:variable name="doc" select="/" />
<xsl:variable name="sortorder" select="document('SortingOrder.xml')" />

<xsl:template match="/myRoot">
<myRoot>
  <xsl:for-each select="$sortorder/mySortingOrder/myElement">
    <xsl:copy-of select="$doc/myRoot/myElement[@key = current()/@key]" />
  </xsl:for-each>
</myRoot>
</xsl:template>

</xsl:stylesheet>

Regards,
Mukul

On 5/11/06, Jagsmiles <jagsmiles@xxxxxxxxx> wrote:
I want to sort the elements of an xml file, The criteria of ordering is
actually specified in another xml file.

Can i use xsl to sort one xml file by the using the ordering data from
another xml file?:

I give a small e.g.

The Original xml file: main.xml

<myRoot>
       <myElement key=3D"Tokyo" country=3D"JAP">I am Tokyo</myElement>
       <myElement key=3D"NewYork" country=3D"US">I am NewYork</myElement>
       <myElement key=3D"Sydney" country=3D"AUS">I am Sydney</myElement>
       <myElement key=3D"London" country=3D"UK">I am London</myElement>
</myRoot>

The Sorting Criteria xml file: SortingOrder.xml:
<mySortingOrder>
       <myElement key=3D"NewYork" />
       <myElement key=3D"London" />
       <myElement key=3D"Tokyo" />
       <myElement key=3D"Sydney" />
</mySortingOrder>


After sorting the final xml data i should get is: <myRoot> <myElement key=3D"NewYork" country=3D"US">I am NewYork</myElement> <myElement key=3D"London" country=3D"UK">I am London</myElement> <myElement key=3D"Tokyo" country=3D"JAP">I am Tokyo</myElement> <myElement key=3D"Sydney" country=3D"AUS">I am Sydney</myElement> </myRoot>

in the final xml, the myElement elements are sorted according to the
sortin=
g
order specified in SortingOrder.xml.

Can i achieve this using xsl?
Normally for the xsl:sort the sorting information should be present in the
element itself.

Thanks in advance.
Jagdishwar.

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.