[xsl] additional question: FO subscript Revisited

Subject: [xsl] additional question: FO subscript Revisited
From: "Tanzila Mohammad" <tmohammad@xxxxxxxxxxxxxxxxxxxx>
Date: Wed, 21 Nov 2001 08:21:19 -0000
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-list


Current Thread