RE: alpha comparison

Subject: RE: alpha comparison
From: "Dave Pawson" <dave.pawson@xxxxxxxxxx>
Date: Thu, 20 Apr 2000 18:24:05 +0100
Many thanks Mike.

Checking understanding,

My input src is
 section
    qna
      topic

I want to check that all qna's are sorted
by topic order.

<xsl:template match="section">
  <xsl:call-template name="is-sorted">
    <xsl:with-param name="nodes" select="qna/topic"/>
  </xsl:call-template>

This passes all topics in this section
to the named templated,
which will bomb out with the message if
the two 'orders' are not equal.

I'm curious why you cast them to string prior
to the comparison? Is it not possible
to compare a result tree fragment held
in the two variables?

Regards, DaveP




Date: Mon, 10 Apr 2000 10:38:47 +0100
From: Kay Michael <Michael.Kay@xxxxxxx>
Subject: RE: alpha comparison
There's no operator to do alphabetic order comparison, the only thing that
does it is xsl:sort.

The simplest way to check that a list of strings is in sorted order is to
sort it and see if the output equals the input. It's probably possible to
improve the following:

<xsl:template name="is-sorted">
   <!-- test whether the document-order of the supplied $nodes
        is the same as the sorted order of their string-values -->
   <xsl:param name="nodes"/>
   <xsl:variable name="unsorted-nodes">
      <xsl:for-each select="$nodes"/>
          <xsl:value-of select="."/>
      </xsl:for-each>
   </xsl:variable>
   <xsl:variable name="sorted-nodes">
      <xsl:for-each select="$nodes"/>
          <xsl:sort/>
          <xsl:value-of select="."/>
      </xsl:for-each>
   </xsl:variable>
   <xsl:if test="string($sorted-nodes) != string($unsorted-nodes)">
      <xsl:message terminate="yes">Data is not correctly
sorted</xsl:message>
   </xsl:if>
</xsl:template>



 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread