This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
RE: using substring-functions more than once in a node?
- From: Wendell Piez <wapiez at mulberrytech dot com>
- To: xsl-list at lists dot mulberrytech dot com
- Date: Tue, 26 Mar 2002 14:25:55 -0500
- Subject: RE: [xsl] using substring-functions more than once in a node?
- Reply-to: xsl-list at lists dot mulberrytech dot com
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@mulberrytech.com
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