This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
RE: alpha comparison
- To: "'xsl-list at mulberrytech dot com'" <xsl-list at mulberrytech dot com>
- Subject: RE: alpha comparison
- From: Kay Michael <Michael dot Kay at icl dot com>
- Date: Mon, 10 Apr 2000 10:38:47 +0100
- Reply-To: xsl-list at mulberrytech dot com
> I need to check if the following-sibling has
> a child with content <tba> than the current node.
> Its a security check to ensure that the input file is
> in sorted order (No I won't say why, its too
> embarassing).
>
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