This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

RE: alpha comparison


> 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

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]