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

Re: String match within block of text

Subject: Re: String match within block of text
From: Jeni Tennison <mail@xxxxxxxxxxxxxxxx>
Date: Thu, 19 Apr 2001 20:04:56 +0100
jeni from the block
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

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.