xsl-list
[Top] [All Lists]

Re: [xsl] Checking alphabetical order

2007-09-23 21:02:46
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


--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

<Prev in Thread] Current Thread [Next in Thread>