[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: additional question: FO subscript

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


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.