|
Subject: Re: [xsl] comparing strings From: Miloslav Nic <nicmila@xxxxxxxxx> Date: Tue, 02 Jan 2001 11:10:56 +0100 |
<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 < $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 |
|---|
|
| <- Previous | Index | Next -> |
|---|---|---|
| [xsl] comparing strings, Oliver Becker | Thread | Re: [xsl] comparing strings, Jeni Tennison |
| [xsl] comparing strings, Oliver Becker | Date | RE: [xsl] multiple XML tags -> sing, Kay Michael |
| Month |