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

RE: using substring-functions more than once in a node

Subject: RE: using substring-functions more than once in a node?
From: Wendell Piez <wapiez@xxxxxxxxxxxxxxxx>
Date: Tue, 26 Mar 2002 14:25:55 -0500
stylusstudio.com xsllist 200203 post01300.html
Mario--

Of course, if your footnotes appeared as markup (e.g. <fn> elements) this would be *so* much easier.

In effect, you're having to use XSLT to parse your own custom markup. Hence the recursive template in David's solution.

You might consider a pre-pass over the data before you use XSLT on it, changing, for example, the regular expression (I use a syntax my text editor knows) "(FN \([0-9]+\))" to "<FN no="\1"/> so you have <FN no="99"/> in your data instead of (FN 99). The transform would then be trivial.

Cheers,
Wendell

At 01:47 PM 3/26/2002, David McNally wrote:
Hi.

You can define a template that matches a footnote, and calls itself
recursively so that it gets them all.  Something like this (untested):

<xsl:template name="doFootnotes">
        <xsl:param name="string"/>
        <xsl:choose>
                <xsl:when test="contains($string,'(FN ')">

                        <xsl:variable name="before">
                                <xsl:value-of
select="substring-before($string,'(FN ')"/>
                        </xsl:variable>
                        <xsl:variable name="number">
                                <xsl:value-of
select="substring(substring-after($string,'(FN '),1,1)"/>
                        </xsl:variable>
                        <xsl:variable name="after">
                                <xsl:value-of
select="substring(substring-after($string,'(FN '),2)"/>
                        </xsl:variable>

                        <xsl:value-of select="$before"/>
                        <xsl:text>(FN </xsl:text>
                        <a>
                                <xsl:attribute name="href">
                                        <xsl:text>#FN_target_</xsl:text>
                                        <xsl:value-of select="$number"/>
                                </xsl:attribute>
                                <xsl:value-of select="$number"/>
                        </a>
                        <xsl:call-template name="doFootnotes">
                                <xsl:with-param name="string"
select="$after"/>
                        </xsl:call-template>
                </xsl:when>
                <xsl:otherwise>
                        <xsl:value-of select="$string"/>
                </xsl:otherwise>
        </xsl:choose>
</xsl:template>

You would then call it somthing like this:

<xsl:template match="para">
        <xsl:call-template name="doFootnotes">
                <xsl:with-param name="string" select="."/>
        </xsl:call-template>
</xsl:template>

This template only works because you say the footnote numbers are only one
digit - if you reached footnote 10, you'd need something cleverer....

Hope this helps,
David.


======================================================================
Wendell Piez                            mailto:wapiez@xxxxxxxxxxxxxxxx
Mulberry Technologies, Inc.                http://www.mulberrytech.com
17 West Jefferson Street                    Direct Phone: 301/315-9635
Suite 207                                          Phone: 301/315-9631
Rockville, MD  20850                                 Fax: 301/315-8285
----------------------------------------------------------------------
  Mulberry Technologies: A Consultancy Specializing in SGML and XML
======================================================================


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.