Re: [xsl] Checking alphabetical order

Subject: Re: [xsl] Checking alphabetical order
From: Wendell Piez <wapiez@xxxxxxxxxxxxxxxx>
Date: Mon, 24 Sep 2007 11:33:37 -0400

How about this idea?

Create a variable containing the string value of an Element with its preceding-sibling::Element[1] (its immediate preceding sibling), concantenated in alphabetical order:

<xsl:variable name="ordered-values">
<xsl:for-each select=". | preceding-sibling::Element[1]">
<xsl:sort data-type="text"/>
<xsl:value-of select="."/>
<xsl:variable name="given-values" select="concat(preceding-sibling::Element[1],.)"/>
<xsl:if test="not($given-values = $ordered-values)">
<xsl:text>A palpable hit!</xsl:text>
<xsl:copy-of select="."/>

This is based on the principle that if an item is out of alphabetical order, it is out of alphabetical order in relation to its immediate predecessor.

I hope this isn't the solution you didn't want us to tell you.


At 06:16 PM 9/23/2007, you wrote:
I would like to compare elements and determine if any element is out of alphabetical order, for XPath 1.0. For example,


I would like this to register that the final element is out of sequence. I thought about doing this with preceding-sibling, unfortunately, it turns out that doesn't work for strings. If they are numbers, I can do it.

For example, if I had numbers, such as,

And I used:

Elements/Element[. &lt; preceding-sibling::node()]

I would get the last element. I suspect I can do this with a template (manually compare the current node to the preceding-sibling), but I was wondering if there was a simple way of doing this.

If there isn't, can you please keep the non simple solution (ie the one where you have to create a template to compare two strings) to yourself as I would like to have a stab at it myself.


Kamal Bhatt

Wendell Piez                            mailto:wapiez@xxxxxxxxxxxxxxxx
Mulberry Technologies, Inc.      
17 West Jefferson Street                    Direct Phone: 301/315-9635
Suite 207                                          Phone: 301/315-9631
Rockville, MD  20850                                 Fax: 301/315-8285
  Mulberry Technologies: A Consultancy Specializing in SGML and XML

Current Thread