[Home] [By Thread] [By Date] [Recent Entries]
Jeff Sese wrote:
It does, by a landslide! It is not handy that "Seite" comes before "seite" comes before "SEITE", but I think your point is that the word doesn't matter, the sort key does. Here's how I would do it: <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="' ', text()"/> </xsl:template> </xsl:stylesheet> I used this as input example: <input> <data>99</data> <data>seite 120</data> <data>seite120</data> <data>Seite 99</data> <data>Seite 120</data> <data>Seite 0120</data> <data>Page 12</data> <data>seite 0012</data> <data>seite120</data> <data>pink rabbit</data> <data>SEITE 120</data> <data>Seite 99</data> <data>0001</data> <data>Seite 12000</data> <data>1200</data> </input> And I got this for output: seite 0012 Seite 99 Seite 99 seite 120 seite120 Seite 120 Seite 0120 seite120 SEITE 120 Seite 12000 0001 99 1200 pink rabbit Page 12 Which is, I believe, about according your rules. Note that the simplest way to put something on top in a sorting order is by extracting its boolean value. Another method is by using .[predicate] where the result is the empty sequence, but that may have some nasty side effects (i.e., when the result is not the empty sequence it will be sorted by its value and in your case, you do not want that). HTH, Cheers, -- Abel Braaksma PS: I chose for replace() in favor of starts-with(lower-case(.), 'seite') because I found it marginally clearer, but that's a matter of taste of course.
|

Cart



