[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: comparing strings

Subject: Re: comparing strings
From: Miloslav Nic <nicmila@xxxxxxxxx>
Date: Tue, 02 Jan 2001 11:10:56 +0100
xsl compare strings
<xsl:stylesheet
        version="1.0"
        xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:output method="xml" indent="yes"/>

<xsl:param name="start">pac</xsl:param>
<xsl:param name="count">5</xsl:param>

<xsl:template match="/">
  <xsl:apply-templates select="//term[starts-with(.,$start)][1]"/>
</xsl:template>

<xsl:template match="term">
  <xsl:param name="pos" select="1"/>
  <t><xsl:value-of select="."/></t>

  <xsl:if test="$pos &lt; $count">
    <xsl:apply-templates select="following-sibling::term[1]">
      <xsl:with-param name="pos" select="$pos + 1"/>
    </xsl:apply-templates>
  </xsl:if>

</xsl:template>

</xsl:stylesheet>



Oliver Becker wrote:
> 
> 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

-- 
******************************************
<firstName> Miloslav </firstName>    
<surname>   Nic      </surname>     

<mail>    nicmila@xxxxxxxxx    </mail>   
<support> http://www.zvon.org  </support>
<zvonMailingList> 
    http://www.zvon.org/index.php?nav_id=4 
</zvonMailingList>

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


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.