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

auto-replacing text with hyperlink

Subject: auto-replacing text with hyperlink
From: "Noelle" <ng302@xxxxxxxxxxx>
Date: Wed, 13 Aug 2003 14:55:28 +0100
xsl hyperlink
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


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.