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(_dot_)c(_at_)thomsondigital(_dot_)com>
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>—</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.
--~------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail:
<mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--
--~------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--