Subject: Re: [xsl] String match within block of text From: Jeni Tennison <mail@xxxxxxxxxxxxxxxx> Date: Thu, 19 Apr 2001 20:04:56 +0100 |
Hei Jarno, The big trouble with this template is that it works through the text one character at a time. So rather than using substring(..., 1, 1)/substring(..., 2) to recurse through the string, it's usually better to use substring-before() and substring-after(). Thus the 'linker' template could instead be: <xsl:template name="linker"> <xsl:param name="text" select="." /> <xsl:variable name="match" select="$specie[contains($text, .)][1]" /> <xsl:choose> <xsl:when test="$match"> <xsl:call-template name="linker"> <xsl:with-param name="text" select="substring-before($text, $match)" /> </xsl:call-template> <font color="#008000"> <i> <a href="{$match/@href}"> <xsl:value-of select="$match" /> </a> </i> </font> <xsl:call-template name="linker"> <xsl:with-param name="text" select="substring-after($text, $match)" /> </xsl:call-template> </xsl:when> <xsl:otherwise><xsl:value-of select="$text" /></xsl:otherwise> </xsl:choose> </xsl:template> The big problem with this solution is that I'm recursing in two places, so I can't take advantage of any tail-end recursion optimisation that the XSLT processor might do. However, it'll still probably be more efficient unless there are *lots* of Specie elements whose values are held in the Synonyms text. Cheers, Jeni (Beethoven: Ode to Joy) --- Jeni Tennison http://www.jenitennison.com/ XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
RE: [xsl] String match within block, Jarno Elovirta | Thread | [xsl] Transformation of generic spr, Xiaocun Xu |
RE: [xsl] Question about linking us, sara . mitchell | Date | RE: [xsl] Namespaces and XML, sara . mitchell |
Month |