[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

[xsl] comparing strings


Subject: [xsl] comparing strings
From: Oliver Becker <obecker@xxxxxxxxxxxxxxxxxxxxxxx>
Date: Tue, 2 Jan 2001 10:28:29 +0100 (MET)

Dear friends,

happy new year to everybody!

Is there someone out there who can answer my simple question:
How to compare strings with XPath/XSLT, something like strcmp() in C
or compareTo() in Java?
I want a pure XSLT solution without using extensions.

For those of you who are interested I have a little use case:

Consider this simplified dictionary:
<longman>
   ...
   <term>oz</term>
   <term>ozone</term>
   <term>p</term>
   <term>pa</term>
   <term>pace</term>
   <term>pacemaker</term>
   <term>pacesetter</term>
   <term>pachyderm</term>
   <term>pacific</term>
   <term>pacifier</term>
   <term>pacifism</term>
   <term>pacifist</term>
   <term>pacify</term>
   <term>pack</term>
   <term>package</term>
   <term>packaged</term>
   <term>packaging</term>
   <term>packed</term>
   <term>packer</term>
   <term>packet</term>
   <term>packing</term>
   <term>pact</term>
   <term>pad</term>
   ...
</longman>

Question: given an arbitrary input term (e.g. as a parameter), how
can I display the next 10 terms, starting with my input or the
term which would follow directly in alphabetical order?

If I had numbers instead of strings, the following template would
solve the required task:

<xsl:param name="input" />

<xsl:template match="term">
   <xsl:if test=". >= $input and
                 not(preceding-sibling::term[10] >= $input)">
      <!-- display . in some appropriate way -->
   </xsl:if>
</xsl:template>

Regards,
Oliver


/-------------------------------------------------------------------\
|  ob|do        Dipl.Inf. Oliver Becker                             |
|  --+--        E-Mail: obecker@xxxxxxxxxxxxxxxxxxxxxxx             |
|  op|qo        WWW:    http://www.informatik.hu-berlin.de/~obecker |
\-------------------------------------------------------------------/

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



Current Thread
Keywords