Hello all,
I have a requirement, where in I am comparing the first and last page
string and manipulating the last page value in output. Though there is
nothing wrong in below stylesheet in terms of output but I am sure there
must be smart way of doing this. May be with use of <xsl:variable>.
Any thoughts will be appreciated.
TIA,
Pankaj
Input
====
<pages><first-page>10635<first-page><last-page>10637<last-page></pages>
Output
=====
<pages><first-page>10635<first-page>-<last-page>7<last-page></pages>
Stylesheet
=======
<xsl:template match="pages">
<xsl:copy>
<xsl:apply-templates select="./first-page"/>
<xsl:choose>
<xsl:when test="./last-page">
<MIT><xsl:text>—</xsl:text></MIT>
<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="substring(.,1,1)=substring(preceding-sibling::first-page,1,1)">
<xsl:if
test="not(substring(.,2,1)=substring(preceding-sibling::first-page,2,1))">
<xsl:value-of select="substring(.,2,string-length(.))"/>
</xsl:if>
<xsl:if
test="not(substring(.,3,1)=substring(preceding-sibling::first-page,3,1))">
<xsl:value-of select="substring(.,3,string-length(.))"/>
</xsl:if>
<xsl:if
test="not(substring(.,4,1)=substring(preceding-sibling::first-page,4,1))">
<xsl:value-of select="substring(.,4,string-length(.))"/>
</xsl:if>
<xsl:if
test="not(substring(.,5,1)=substring(preceding-sibling::first-page,5,1))">
<xsl:value-of select="substring(.,5,string-length(.))"/>
</xsl:if>
<xsl:if
test="not(substring(.,6,1)=substring(preceding-sibling::first-page,6,1))">
<xsl:value-of select="substring(.,6,string-length(.))"/>
</xsl:if>
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates/>
</xsl:otherwise>
</xsl:choose>
</xsl:copy>
</xsl:template>
--~------------------------------------------------------------------
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>
--~--