Altova Mailing List Archives
>xsl-list Archive Home
>Recent entries
>Thread Prev - Re: [xsl] additional question: FO subscript
>Thread Next - Re: [xsl] additional question: FO subscript Revisited
[xsl] additional question: FO subscript Revisited
To:
Date: 11/20/2001 10:21:00 PM
Thanks.
Just a question, I have used the code but I am trying to manipulate it so
that as well as a 2 it subscripts a 5. But this time the row information is
duplicated - any suggestions?
......
<xsl:template name="replace2s">
<xsl:param name="string" select="string()" />
<xsl:variable name="subscript2">
<fo:inline baseline-shift="sub" font-size="6px">2</fo:inline>
</xsl:variable>
<xsl:variable name="subscript5">
<fo:inline baseline-shift="sub" font-size="6px">5</fo:inline>
</xsl:variable>
<xsl:choose>
<xsl:when test="contains($string, '2') or contains($string, '5')">
<xsl:if test="contains($string, '2')">
<xsl:value-of select="substring-before($string, '2')" />
<xsl:copy-of select="$subscript2" />
<xsl:call-template name="replace2s">
<xsl:with-param name="string"
select="substring-after($string, '2')" />
</xsl:call-template>
</xsl:if>
<xsl:if test="contains($string, '5')">
<xsl:value-of select="substring-before($string, '5')" />
<xsl:copy-of select="$subscript5" />
<xsl:call-template name="replace2s">
<xsl:with-param name="string"
select="substring-after($string, '5')" />
</xsl:call-template>
</xsl:if>
</xsl:when>
<xsl:otherwise><xsl:value-of select="$string" /></xsl:otherwise>
</xsl:choose>
</xsl:template>
......
Template was called as follows:
<xsl:for-each select="./faostat:row-title">
<xsl:call-template name="replace2s"/>
</xsl:for-each>
Tanz
-----Original Message-----
From: owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx
[mailto:owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx]On Behalf Of Jeni Tennison
Sent: 20 November 2001 16:05
To: Tanzila Mohammad
Cc: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: Re: [xsl] additional question: FO subscript
Hi Tanzila,
> I want to give the 'subscript of 2' a variable name so that it can
> be used later:
You don't need the xsl:value-of - you only use xsl:value-of if you
want to insert the (string) value of some expression. Instead, just
use:
<xsl:variable name="subscript2">
<fo:inline baseline-shift="sub" font-size="6px">2</fo:inline>
</xsl:variable>
This sets the $subscript2 variable to a result tree fragment, which
looks like a little node tree with a root node and a child fo:inline
element with a value of 2.
To insert that result tree fragment into your result, preserving its
structure, you use:
<xsl:copy-of select="$subscript2" />
You can't use translate() to substitute the '2' characters in a string
with the value of that variable, however. The translate() function
only works with exchanging one set of characters for another set of
characters. To replace the '2' characters in a string with the
subscripted 2, you need:
<xsl:value-of select="substring-before(., '2')" />
<xsl:copy-of select="$subscript2" />
<xsl:value-of select="substring-after(., '2')" />
or, if there are lots of '2' characters in the string, you need a
recursive template:
<xsl:template name="replace2s">
<xsl:param name="string" select="string()" />
<xsl:variable name="subscript2">
<fo:inline baseline-shift="sub" font-size="6px">2</fo:inline>
</xsl:variable>
<xsl:choose>
<xsl:when test="contains($string, '2')">
<xsl:value-of select="substring-before($string, '2')" />
<xsl:copy-of select="$subscript2" />
<xsl:call-template name="replace2s">
<xsl:with-param name="string"
select="substring-after($string, '2')" />
</xsl:call-template>
</xsl:when>
<xsl:otherwise><xsl:value-of select="$string" /></xsl:otherwise>
</xsl:choose>
</xsl:template>
You can call this with:
<xsl:for-each select="row-title">
<xsl:call-template name="replace2s" />
</xsl:for-each>
I hope that helps,
Jeni
---
Jeni Tennison
http://www.jenitennison.com/
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-listDisclaimer
These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

