[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: String match within block of text
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
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|