RE: [xsl] using substring-functions more than once in a node?

Subject: RE: [xsl] using substring-functions more than once in a node?
From: "McNally, David" <David.McNally@xxxxxxxxxx>
Date: Tue, 26 Mar 2002 13:47:24 -0500
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.
--
David McNally            Moody's Investors Service
Software Engineer        99 Church St, NY NY 10007 
David.McNally@xxxxxxxxxx            (212) 553-7475 


> -----Original Message-----
> From: Mario Michlits [mailto:mario.michlits@xxxxxxxx]
> Sent: Tuesday, March 26, 2002 1:00 PM
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject: [xsl] using substring-functions more than once in a node?
> 
> 
> Hello
> 
> I m experimenting with substring functions to markup footnote 
> references in my text.
> For example I got following element:
> 
> <para>This is my first sentence (FN 1). And this is the last 
> one (FN 2).</para>
> 
> What I want is to markup the footnote's numbers as HTML 
> <a>-elements. A footnote always has this format: (FN [1-9])
> This is done by the following code:


---------------------------------------

The information contained in this e-mail message, and any attachment thereto, is confidential and may not be disclosed without our express permission.  If you are not the intended recipient or an employee or agent responsible for delivering this message to the intended recipient, you are hereby notified that you have received this message in error and that any review, dissemination, distribution or copying of this message, or any attachment thereto, in whole or in part, is strictly prohibited.  If you have received this message in error, please immediately notify us by telephone, fax or e-mail and delete the message and all of its attachments.  Thank you.

Every effort is made to keep our network free from viruses.  You should, however, review this e-mail message, as well as any attachment thereto, for viruses.  We take no responsibility and have no liability for any computer virus which may be transferred via this e-mail message.


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread