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

Re: Attribute-based XML Sorting using XSL

Subject: Re: Attribute-based XML Sorting using XSL
From: Matt Jones <xsl-list@xxxxxxxxxxxxx>
Date: Mon, 17 Jun 2002 15:25:15 -0700
attribute based xml
Where my problem is in building the sort query. With the data in the format it is in, how can I write the xsl:sort statement to sort using the value attribute, based upon the name attribute?
(eg. sort the items in Col2)
Again, any help is much appreciated.


Peace,

Matt

Chris Bayes wrote:

http://benbayes/xml/index.xml?/xml/tutorial/filtering/filter.xml

XML/XSL Portal
http://www.bayes.co.uk/xml




-----Original Message-----
From: owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx [mailto:owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx] On Behalf Of Matt Jones
Sent: 17 June 2002 20:41
To: 'XSL-List@xxxxxxxxxxxxxxxxxxxxxx'
Subject: Attribute-based XML Sorting using XSL



Hello,
I have an XML file which rather generically describes the information to display in an HTML table, like so:
<?xml version="1.0" encoding="utf-8" ?>
<?xml-stylesheet type="text/xsl" href="attribute-sort.xsl" ?>
<ROWSET>
<ROW>
<COLUMN name="Col1" value="4-1" />
<COLUMN name="Col2" value="4-2" />
<COLUMN name="Col3" value="4-3" />
</ROW>
<ROW>
<COLUMN name="Col1" value="1-1" />
<COLUMN name="Col2" value="1-2" />
<COLUMN name="Col3" value="1-3" />
</ROW>
<ROW>
<COLUMN name="Col1" value="3-1" />
<COLUMN name="Col2" value="3-2" />
<COLUMN name="Col3" value="3-3" />
</ROW>
<ROW>
<COLUMN name="Col1" value="2-1" />
<COLUMN name="Col2" value="2-2" />
<COLUMN name="Col3" value="2-3" />
</ROW>
</ROWSET>


And an XSL file which creates an HTML table, like so:

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

   <xsl:template match="/">
       <HTML><BODY>
           <xsl:apply-templates select="ROWSET"/>
       </BODY></HTML>
   </xsl:template>

<xsl:template match="ROWSET">
<TABLE border="1" cellspacing="0" cellpadding="0">
<TR STYLE="font-size:x-small;">
<xsl:for-each select="ROW[position()=1]/COLUMN">
<xsl:value-of select="@name"/>
</xsl:for-each>
</TR> <xsl:apply-templates select="ROW">
<xsl:sort select="COLUMN[@value]"/>
</xsl:apply-templates>
</TABLE>
</xsl:template>


<xsl:template match="ROW">
<!-- Output rows of the table -->
<TR STYLE="font-size:x-small;">
<xsl:for-each select="COLUMN">
<TD valign="top"><xsl:apply-templates select="@value"/>&#160;</TD>
</xsl:for-each>
</TR>
</xsl:template>
</xsl:stylesheet>


My problem is that I'd like to be able to sort on a column name. That is to say, I'd like to be able to sort the ROWs in the order of the @value attribute for the COLUMN which has a matching @name attribute. This is rather difficult to explain--think about a list control where you can click any of the headers and sort the entire list based upon that column.

To keep this as generic as possible, I don't really want to change the XML, only the XSL.

Any help would be greatly appreciated.

Peace,

Matt


XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list











XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list



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-2011 All Rights Reserved.