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

Re: generic sort based on attribute names

Subject: Re: generic sort based on attribute names
From: Dimitre Novatchev <dnovatchev@xxxxxxxxx>
Date: Mon, 24 Jan 2005 05:54:49 +1100
generic sort
On Sun, 23 Jan 2005 17:37:24 -0000, Michael Kay <mike@xxxxxxxxxxxx> wrote:
> This is quite tricky in XSLT 1.0 as the sort key has to be expressed as an
> XPath expression, it can't be computed using XSLT code. In 2.0 (a) XPath
> expressions are more powerful, and (b) you can do an XSLT computation inside
> the xsl:sort.
> 
> Here's a solution using the latter approach:
> 
> <xsl:for-each select="e">
>  <xsl:sort>
>    <xsl:for-each select="@*">
>      <xsl:sort select="name()"/>
>      <xsl:value-of select='name(), "=""", ., """ "' separator=""/>
>    </xsl:for-each>
>  </xsl:sort>
>  <xsl:copy-of select="."/>
> </xsl:for-each>
> 
> Not tested; and note (a) this doesn't handle namespaces, and (b) it doesn't
> attempt to change the order of attributes in the output, since that's not
> under XSLT's control anyway.
> 
> Michael Kay
> http://www.saxonica.com/

Saxon 8.2 produces an error message that:

"A sequence of more than one item is not allowed as the @sort-key
attribute of xsl:sort".

Besides this problem, does xsl:sort have a "sort-key" attribute? I
don't see it specified either in the latest WG draft or in the book.


Cheers,
Dimitre.



> 
> > -----Original Message-----
> > From: Chaitanya Desai [mailto:cdesai@xxxxxxxxxxx]
> > Sent: 23 January 2005 03:23
> > To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> > Subject:  generic sort based on attribute names
> >
> >
> > Hi,
> > I am trying to write a generic sort that uses the 'concatenated
> > name-value pairs of all attributes sorted' as the key to sort
> > elements
> > at a particular level.
> > Example
> > Suppose
> > <root>
> >  <e b="bb" y="yy"/>
> >  <e z="zz" a="aa"/>
> > </root>
> > is the XML I want to sort.
> > The result of the sort should be
> > <root>
> >   <e a="aa" z="zz" />
> >   <e b="bb" y="yy" />
> > </root>
> > Thus the attributes within an element are sorted and then the
> > key used
> > for sorting elements would be:
> > 'az' and 'by' respectively (thus 'az' < 'by').
> > I am able to sort attributes within an element.
> > But I am having trouble setting the key to sort for elements.
> > Any help would be greatly appreciated.
> > Thanks
> > Chaitanya

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.