Subject: [xsl] auto-replacing text with hyperlink From: "Noelle" <ng302@xxxxxxxxxxx> Date: Wed, 13 Aug 2003 14:55:28 +0100 |
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 |
---|
|
<- Previous | Index | Next -> |
---|---|---|
RE: [xsl] pass malformed HTML throu, cknell | Thread | Re: [xsl] auto-replacing text with , Cina Zone |
RE: [xsl] how to close html tags : , Julian Reschke | Date | Re: [xsl] pass malformed HTML throu, Jeff Kenton |
Month |