|
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:
<xsl:sort
select="translate(concat(.,self::*[contains(.,'-')]
^^^
/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>ABC-</word>
<word>spirit-level</word>
<word type="end">DEF</word>
should presumably be output/sorted as:
ABCDEF
spirit-level
rather than:
ABCDEF
spiritDEF
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()) != '-'],
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
---
Jeni Tennison
http://www.jenitennison.com/
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
| Current Thread |
|---|
|
| <- Previous | Index | Next -> |
|---|---|---|
| RE: [xsl] Sort problem, Mick | Thread | [xsl] i18n approach, Andreas Müller |
| [xsl] White space in HTML result??, by way of Mulberry T | Date | RE: [xsl] Using document() without , Edmund Mitchell |
| Month |