Re: [xsl] Sort problem

Subject: Re: [xsl] Sort problem
From: Jeni Tennison <mail@xxxxxxxxxxxxxxxx>
Date: Mon, 5 Feb 2001 14:58:39 +0000
Hi Mick,

Dimitre wrote:
> The xsl:sort element in the previous stylesheet must be modified to the
> following:
> <xsl:sort 
> select="translate(concat(.,self::*[contains(.,'')]
> /following::word[@type='end']), '-', '')"/>

but meant:

/following::word[@type='end']), '-', '')" />

Brilliantly insightful solution.

Just to explain why the stuff I wrote used lots of substring() and
string-length() all over the place: I was assuming that there might be
words that contained hyphens in the middle of them.  For example:

  <word type="end">DEF</word>

should presumably be output/sorted as:


rather than:


Of course it might not be a problem with the input that you're using,
but if it is, then you need to substitute:

  contains(., '-')      -> substring(., string-length()) = '-'
  string-before(., '-') -> substring(., 1, string-length() - 1)

and of course using the translate() function will get rid of *all* the
hyphens in the words, which may or may not be helpful. The safest
solution is probably:

concat(substring(., 1, string-length() - 1),
       substring(self::node()[substring(., string-length()) != '-'],
       self::node()[substring(., string-length()) = '-']
          /following::word[@type = 'end'])

But of course you should use the simplest that you can get away with.

I hope that helps,


Jeni Tennison

 XSL-List info and archive:

Current Thread