Conal,
Thanks! That worked. Here's the result...
XML ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
<para>The completion chemical is <chemical>H2OClF3H4</chemical> for this
test.</para>
XSL ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
<xsl:template match="chemical">
<xsl:variable name="this_chemical" select="."/>
<xsl:call-template name="chemical_formater">
<xsl:with-param name="formula" select="."/>
</xsl:call-template>
</xsl:template>
<xsl:template name="chemical_formater">
<xsl:param name="formula"/>
<xsl:variable name="each_char" select="substring($formula,1,1)"/>
<xsl:choose>
<xsl:when test="$each_char='1' or $each_char='2' or $each_char='3' or
$each_char='4' or $each_char='5' or $each_char='6' or $each_char='7' or
$each_char='8' or $each_char='9' or $each_char='0'">
<fo:inline baseline-shift="sub" font-size="75%">
<xsl:value-of select="$each_char"/>
</fo:inline>
</xsl:when>
<xsl:otherwise>
<fo:inline baseline-shift="normal">
<xsl:value-of select="$each_char"/>
</fo:inline>
</xsl:otherwise>
</xsl:choose>
<xsl:if test="substring-after($formula,$each_char)!=''">
<xsl:call-template name="chemical_formater">
<xsl:with-param name="formula">
<xsl:value-of
select="substring-after($formula,$each_char)"/>
</xsl:with-param>
</xsl:call-template>
</xsl:if>
</xsl:template>
XSL-FO ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
<fo:block>
The completion chemical is
<fo:inline baseline-shift="normal">H</fo:inline>
<fo:inline baseline-shift="sub"
font-size="75%">2</fo:inline>
<fo:inline baseline-shift="normal">O</fo:inline>
<fo:inline baseline-shift="normal">C</fo:inline>
<fo:inline baseline-shift="normal">l</fo:inline>
<fo:inline baseline-shift="normal">F</fo:inline>
<fo:inline baseline-shift="sub"
font-size="75%">3</fo:inline>
<fo:inline baseline-shift="normal">H</fo:inline>
<fo:inline baseline-shift="sub"
font-size="75%">4</fo:inline>
for this test.</fo:block>
I appreciate the push through the mental block! On to the next challenge.
Kevin
-----Original Message-----
From: Conal Tuohy [mailto:conalt(_at_)paradise(_dot_)net(_dot_)nz]
Sent: Wednesday, October 30, 2002 5:08 PM
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: RE: [xsl] String Manipulation - Distinguishing alphas and
numerics in a string
You need to write a template with a name attribute, and call it to process
the string. Pass the string to it as a parameter. This template would handle
the first part of the string, then if there's any string remaining, it
should call itself, passing itself the remainder of the string.
Kevin wrote:
Does anyone know how to do this? (the chemistry is not the
issue, I realize
this is a bogus combination)
XML source:
<para>candybars are made of <chemical>H20ClF3</chemical>.</para>
XSL needed?????
<xsl:template match="chemical">
<xsl:variable name="this_chemical" select="."/>
<!-- This is the part I'm stuck on. How do I process the string? The
translate function only wants to replace something. How do I
walk through
the string and wrap each number with the FO for subscript? -->
</xsl:template>
XSL-FO desired:
<fo:block>water is made of H<fo:inline baseline-shift="sub"
2</fo:inline>OClF<fo:inline baseline-shift="sub"
3</fo:inline>.</fo:block>
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list