[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: sort by predefined order
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
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|