This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Re: Attribute-based XML Sorting using XSL
- From: Matt Jones <xsl-list at mattjones dot org>
- To: XSL-List at lists dot mulberrytech dot com
- Date: Mon, 17 Jun 2002 15:25:15 -0700
- Subject: Re: [xsl] Attribute-based XML Sorting using XSL
- References: <A4E84C0DE2891541B51BC39A01B3C4D2119453@libra.swiftnet.tek>
- Reply-to: xsl-list at lists dot mulberrytech dot com
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@lists.mulberrytech.com
[mailto:owner-xsl-list@lists.mulberrytech.com] On Behalf Of Matt Jones
Sent: 17 June 2002 20:41
To: 'XSL-List@lists.mulberrytech.com'
Subject: [xsl] 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"/> </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