i think it would only turn the first instance,just as you wished
I'd like to have the XSLT automatically turn certain words into a link (a
glossary definition), but I'm having some problems doing this. I've managed
to find a search-and-replace template on the net and I've tailored it to
turn the specified word into a link. It seems to be working so far, although
I'm not sure if this is best way to do it. However, I'd like to have it turn
only the *first* instance of the word into a link instead of every instance
on the page. Any suggestions of how I can do this?
(I'd love to buy an XSLT book for reference, but I'm afraid my student
budget doesn't let me afford it, thus, I ask here.)
Here's what I have so far:
----------
<xsl:variable name="term" as="xs:string">stratigraphy</xsl:variable>
<xsl:template match="text()">
<xsl:call-template name="definition">
<xsl:with-param name="text" select="."/>
<xsl:with-param name="from" select="$term"/>
<xsl:with-param name="to">
<![CDATA[<a href="glossary.asp?term=]]><xsl:value-of
select="$term"/><![CDATA[">]]><xsl:value-of select="$term"/><![CDATA[</a>]]>
</xsl:with-param>
</xsl:call-template>
</xsl:template>
<xsl:template name="definition">
<xsl:param name="text"/>
<xsl:param name="from"/>
<xsl:param name="to"/>
<xsl:choose>
<xsl:when test="contains($text, $from)">
<xsl:variable name="before" select="substring-before($text, $from)"/>
<xsl:variable name="after" select="substring-after($text, $from)"/>
<xsl:value-of select="$before"/>
<xsl:value-of select="$to" disable-output-escaping="yes"/>
<xsl:value-of select="$after"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$text"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
---------
Thanks for the help!
Noelle
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list