Re: [xsl] Checking alphabetical order

Subject: Re: [xsl] Checking alphabetical order
From: Kamal Bhatt <kbhatt@xxxxxxxxx>
Date: Mon, 24 Sep 2007 14:06:37 +1000
Deborah Pickett wrote:
On Mon, September 24, 2007 08:16, Kamal Bhatt wrote:
Hi,
I would like to compare elements and determine if any element is out of
alphabetical order, for XPath 1.0. For example,
[...]

Although there isn't an XPath 1.0 operator for string comparison, XSLT 1.0
still has to be able to compare strings because of <xsl:sort>.

So you could apply-templates or for-each on the list, using <xsl:sort> to
sort alphabetically, and then flag any element where its position() !=
count(preceding-sibling::*) + 1.

I'm not certain that it's any prettier. Because you are using
apply-templates/for-each (which conceptually does its items in parallel),
you can't stop after flagging the first out-of-order item. You are also
at the mercy of your locale as to what "alphabetical order" is. That may
or may not matter to you.
That isn't a bad way of doing it if you want to flag all values after the first. I need the functionality to check schema definitions, so it wouldn't be good for me. It never occurred to me that preceding-sibling would leave the XML intact (don't know why).

For my own curiousity, does XSLT 2.0/XPath 2.0 get around this limitation?


-- Kamal Bhatt

Current Thread