This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Re: additional question: FO subscript
- From: Jeni Tennison <jeni at jenitennison dot com>
- To: "Tanzila Mohammad" <tmohammad at entier-solutions dot com>
- Cc: xsl-list at lists dot mulberrytech dot com
- Date: Tue, 20 Nov 2001 16:05:11 +0000
- Subject: Re: [xsl] additional question: FO subscript
- Organization: Jeni Tennison Consulting Ltd
- References: <EBEKJPOMOCIKIIPPEBHBKELLCHAA.tmohammad@entier-solutions.com>
- Reply-to: xsl-list at lists dot mulberrytech dot com
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