Re: [xsl] sort by predefined order

Subject: Re: [xsl] sort by predefined order
From: "Mukul Gandhi" <gandhi.mukul@xxxxxxxxx>
Date: Tue, 20 May 2008 12:06:13 +0530
Below is a XSLT 2.0 solution for this:

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

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

  <xsl:template match="/">
    <xsl:variable name="x" select="source" />
    <target>
      <elements>
        <xsl:for-each select="tokenize($x/sortorder,',')">
          <xsl:copy-of select="$x/elements/element[@ID =
normalize-space(current())]" />
        </xsl:for-each>
     </elements>
    </target>
  </xsl:template>

</xsl:stylesheet>

On 5/20/08, marentxml <mailing.lists@xxxxxxxxxxxx> wrote:
> hi
>
> is there any way to sort elements by a predefined order? i'd like to come
> from
>
> <source>
>  <sortorder>46, 21, 39, 27, 17</sortorder>
>  <elements>
>    <element ID="17"/>
>    <element ID="21"/>
>    <element ID="27"/>
>    <element ID="39"/>
>    <element ID="46"/>
>  </elements>
> </source>
>
> the most elegant way to
>
> <target>
>  <elements>
>    <element ID="46"/>
>    <element ID="21"/>
>    <element ID="39"/>
>    <element ID="27"/>
>    <element ID="17"/>
>  </elements>
> </target>
>
> thanks in advance for any help.
>
> frank


-- 
Regards,
Mukul Gandhi

Current Thread