xsl-list
[Top] [All Lists]

Re: [xsl] Sorting with Different Sort Keys

2007-10-19 02:16:29
Abel Braaksma wrote:

<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>
     <xsl:template match="input">
       <xsl:apply-templates select="data">
                     <!-- sort the 'seite' first -->
<xsl:sort select="matches(., '\s*seite', 'i')" order="descending" />
                     <!-- sort the non-correct ones last -->
<xsl:sort select="not(matches(., '^\d+$'))" order="ascending" />
                     <!-- sort everything by its numeric value -->
<xsl:sort select="replace(., '\D', '')" order="ascending" data-type="number" />
       </xsl:apply-templates>
   </xsl:template>
     <xsl:template match="data">
       <xsl:sequence select="'&#10;', text()"/>
   </xsl:template>
  </xsl:stylesheet>


why does Thunderbird always messes with my XSLT like that? It looked much prettier before posting... Here's a new try of the core part:

<xsl:sort select="matches(., '\s*seite', 'i')" order="descending"  />
<xsl:sort select="not(matches(., '^\d+$'))" order="ascending"  />
<xsl:sort select="replace(., '\D', '')" order="ascending" data-type="number" />


note that technically the last line is semantically equivalent with the last line posted by Michael (and my order="ascending" is redundant):

<xsl:sort select="number(replace(., '[^0-9]', ''))"/>

Cheers,
-- Abel



--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--