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

Re: general string replace problem

Subject: Re: general string replace problem
From: "Chris Nolte" <nolte@xxxxxxxxxxxxxxx>
Date: Thu, 7 Jun 2001 11:22:39 -0700
string replace problem
Marvelous.  Thanks Jeni!

Your first fix solves the problem; the second solution works also.  I'm sure
you're right the latter is more efficient, but my transformations so far are
so short and simple that they take less than a second to execute.  But I'll
happily use your more efficient template anyway.

Note to DaveP: you may want to update the FAQ to point to this corrected
version of Jeni's general string replace template.

----- Original Message -----
From: "Jeni Tennison" <mail@xxxxxxxxxxxxxxxx>
To: "Chris Nolte" <nolte@xxxxxxxxxxxxxxx>
Cc: <xsl-list@xxxxxxxxxxxxxxxxxxxxxx>
Sent: Thursday, June 07, 2001 10:22 AM
Subject: Re:  general string replace problem


> Hi Chris,
>
> > I'm still having problems using Jeni Tennison's general string
> > replace template discussed in the FAQ:
> > http://www.dpawson.co.uk/xsl/stringreplace.html#d44e34517
>
> Oh dear.  The problem is that the $search parameter in the
> replace_strings template is being set through a result tree fragment
> rather than through the select attribute.  That means that when it's
> used in the predicate later on, it's interpreted as boolean true
> rather than as a number.  If you just change that to:
>
>   <xsl:param name="search" select="1" />
>
> it should work better.
>
> However, I'd amend the template in any case to make it more efficient
> by passing the node set of foo:search elements rather than an index
> into that set (which means you're going off and finding it each time):
>
> <xsl:template name="replace_strings">
>   <xsl:param name="input_text" />
>   <xsl:param name="search"
>       select="document('')/*/foo:string_replacement/foo:search" />
>   <xsl:variable name="replaced_text">
>     <xsl:call-template name="replace-substring">
>       <xsl:with-param name="text" select="$input_text" />
>       <xsl:with-param name="from" select="$search[1]/foo:find" />
>       <xsl:with-param name="to" select="$search[1]/foo:replace" />
>     </xsl:call-template>
>   </xsl:variable>
>   <xsl:choose>
>     <xsl:when test="$search[2]">
>       <xsl:call-template name="replace_strings">
>         <xsl:with-param name="input_text" select="$replaced_text" />
>         <xsl:with-param name="search" select="$search[position() > 1]" />
>       </xsl:call-template>
>     </xsl:when>
>     <xsl:otherwise>
>       <xsl:value-of select="$replaced_text" />
>     </xsl:otherwise>
>   </xsl:choose>
> </xsl:template>
>
> I hope that helps,
>
> Jeni
>
> ---
> 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.