This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Re: Sort problem
- To: mick at telekabel dot nl
- Subject: Re: [xsl] Sort problem
- From: Jeni Tennison <mail at jenitennison dot com>
- Date: Mon, 5 Feb 2001 14:58:39 +0000
- CC: xsl-list at lists dot mulberrytech dot com
- Organization: Jeni Tennison Consulting Ltd
- References: <20010205125403.21921.qmail@web6303.mail.yahoo.com>
- Reply-To: xsl-list at lists dot mulberrytech dot com
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