Re: [xsl] XSL Decending Order Query

Subject: Re: [xsl] XSL Decending Order Query
From: Mitch Amiano <mitch.amiano@xxxxxxxxxxxxxxxxxxxx>
Date: Sun, 03 Nov 2002 18:41:18 -0500
The sort element shouldn't contain your table elements: it should be empty. It is used to specify the sorting information and doesn't have contents. The content
should nest within the for-each only.


For sorting, you specify a string expression that turns some input in your source document into a sortable string. Typically it would be an XPath to a child element with text content, or an attribute. Remember too that for-each changes what "." means.

Refer to this template. It may or may not work for your XML input (particularly depending on whether the date element is formatted conveniently), but should at least show you how you might change your own stylesheet.

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

<xsl:output method="text"/>

<xsl:template match="/">
By Title, descending:

   <xsl:for-each select="archive/news">
   <xsl:sort select="article" order="descending"/>
      <xsl:value-of select="title"/>
   </xsl:for-each>

By Date, descending:
<xsl:for-each select="archive/news">
<xsl:sort select="date" order="descending"/>
<xsl:value-of select="date"/>, <xsl:value-of select="title"/>
</xsl:for-each>


</xsl:template>

</xsl:stylesheet>


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



Current Thread