[XSL-LIST Mailing List Archive Home]
[By Thread]
[By Date]
Re: [xsl] auto-replacing text with hyperlink
Subject: Re: [xsl] auto-replacing text with hyperlink From: "Noelle" <ng302@xxxxxxxxxxx> Date: Thu, 14 Aug 2003 11:23:02 +0100 |
Unfortunately it doesn't. When I used exactly the same template with the XML document I have, it changed every instance of the word into a hyperlink. I had hoped it would only do it once as well, since it doesn't call the template again, but alas, it still changes every instance of the word. I thought it might have something to do with the the match="text()" part, but I didn't know any other way to get it to pull the word out of the text without it being in an element of it's own. ----- Original Message ----- From: "Cina Zone" <zfyzhangji@xxxxxxx> To: <xsl-list@xxxxxxxxxxxxxxxxxxxxxx> Sent: Thursday, August 14, 2003 4:22 AM Subject: Re: [xsl] auto-replacing text with hyperlink 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
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] auto-replacing text with , Cina Zone | Thread | Re: [xsl] auto-replacing text with , David Carlisle |
[xsl] RE: CALS Tables & CSS, smiley | Date | Re: [xsl] passing variable through , David Carlisle |
Month |