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

Re: String comparison

Subject: Re: String comparison
From: Wolfgang Laun <wolfgang.laun@xxxxxxxxx>
Date: Fri, 24 Sep 2010 11:43:34 +0200
Re:  String comparison
Here's a  function:

<xsl:function name="wl:trdif">
  <xsl:param name="a" as="xsd:string"/>
  <xsl:param name="b" as="xsd:string"/>
  <xsl:choose>
    <xsl:when test="string-length($a) = 0 or
                    substring($a,1,1) != substring($b,1,1)">
      <xsl:value-of select="$b"/>
    </xsl:when>
    <xsl:otherwise>
      <xsl:value-of select="wl:trdif(substring($a,2),substring($b,2))"/>
    </xsl:otherwise>
  </xsl:choose>
</xsl:function>

<xsl:template match="row">
  <xsl:value-of select="wl:trdif(@a,@b)"/>
</xsl:template>

--------------Input:
<table>
  <row a="123456" b="123456"/>
  <row a="123456" b="12345Z"/>
  <row a="123456" b="1234Y6"/>
  <row a="123456" b="123X56"/>
  <row a="123456" b="12W456"/>
  <row a="123456" b="1V3456"/>
  <row a="123456" b="U23456"/>
</table>

--------------Output:

  Z
  Y6
  X56
  W456
  V3456
  U23456


On 24 September 2010 11:01, <pankaj.c@xxxxxxxxxxxxxxxxxx> wrote:
>
> Modified version compares upto 6 digits/characters. BUT I STILL BELIEVE
> there must be better way:
>
>
>    <xsl:template match="pages">
>          <xsl:copy>
>            <xsl:apply-templates select="./first-page"/>
>            <xsl:choose>
>                <xsl:when test="./last-page">
>                    <xsl:text>&#x2014;</xsl:text>
>                    <xsl:apply-templates select="./last-page"/>
>                </xsl:when>
>            </xsl:choose>
>        </xsl:copy>
>    </xsl:template>
>
>
> <xsl:template match="last-page">
> <xsl:copy>
>  <xsl:choose>
>    <xsl:when
> test="not(string-length(.)=string-length(preceding-sibling::first-page))
> or string-length(.)=1">
>         <xsl:apply-templates/>
>     </xsl:when>
>    <xsl:when test="string(.)=string(preceding-sibling::first-page)">
>         <xsl:apply-templates/>
>     </xsl:when>
>     <xsl:otherwise>
>        <xsl:choose>
>            <xsl:when test="not(substring(.,2,1) =
> substring(preceding-sibling::first-page,2,1))">
>                   <xsl:value-of
> select="substring(.,2,string-length(.))"/>
>            </xsl:when>
>            <xsl:when test="not(substring(.,3,1) =
> substring(preceding-sibling::first-page,3,1))">
>                   <xsl:value-of
> select="substring(.,3,string-length(.))"/>
>            </xsl:when>
>            <xsl:when test="not(substring(.,4,1) =
> substring(preceding-sibling::first-page,4,1))">
>                   <xsl:value-of
> select="substring(.,4,string-length(.))"/>
>            </xsl:when>
>            <xsl:when test="not(substring(.,5,1) =
> substring(preceding-sibling::first-page,5,1))">
>                   <xsl:value-of
> select="substring(.,5,string-length(.))"/>
>            </xsl:when>
>            <xsl:when test="not(substring(.,6,1) =
> substring(preceding-sibling::first-page,6,1))">
>                   <xsl:value-of
> select="substring(.,6,string-length(.))"/>
>            </xsl:when>
>            <xsl:otherwise>
>                 <xsl:apply-templates/>
>            </xsl:otherwise>
>        </xsl:choose>
>   </xsl:otherwise>
>  </xsl:choose>
>  </xsl:copy>
>  </xsl:template>
>
>
>
>
>
> Ooooooooops, this seems to be not correct as it gives incorrect output for
>
> few cases.
>
> Thanks for reading anyway....... getting this done again.

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-2011 All Rights Reserved.