Re: [xsl] additional question: FO subscript

Subject: Re: [xsl] additional question: FO subscript
From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx>
Date: Tue, 20 Nov 2001 16:05:11 +0000
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

  <xsl:variable name="subscript2">
    <fo:inline baseline-shift="sub" font-size="6px">2</fo:inline>

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: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:otherwise><xsl:value-of select="$string" /></xsl:otherwise>

You can call this with:

  <xsl:for-each select="row-title">
    <xsl:call-template name="replace2s" />

I hope that helps,


Jeni Tennison

 XSL-List info and archive:

Current Thread