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

Re: Recursion not recursing, or not passing parameter.

Subject: Re: Recursion not recursing, or not passing parameter. Multiple search/ replace.
From: "David Carlisle d.p.carlisle@xxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Thu, 17 Dec 2015 12:14:43 -0000
Re:  Recursion not recursing
On 17 December 2015 at 11:56, Kerry, Richard richard.kerry@xxxxxxxx <
xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> wrote:

>
>
> I am trying to write an XSLT stylesheet that does a multiple search and
> replace.  In order to make it work with multiple search/replace string
> pairs I think I need to use recursion, calling the built-in replace
> function for each pair.  However I don't seem to be getting the parameter
> set, or used, properly when I try to do the recursive call to do the next
> pair.
>
>
>
> I set up the pairs in a sequence of elements as follows:
>
>  <xsl:variable name="replace-spec" >
>    <replace source="smith_component" replacement="{$new-name}" />
>
>    <replace source="$ref-uuid-1" replacement="{$new-uuid-1}" />
>    <replace source="$ref-uuid-2" replacement="{$new-uuid-2}" />
>
>  </xsl:variable>
>
> That's passed to my replace function, along with the source string that
> needs all the replacements done.
>
>  <xsl:variable name="template-text-2" as="xs:string"
> select="my:replace-sequence( $template-text, $replace-spec )" />
>
> The replace-sequence function is supposed to call (built-in
> function) "replace()" using the first element in the spec, then recurse and
> call itself with the first result string and the remainder of the spec (if
> there is any remainder).  As follows.
>
>
>
> <xsl:function name="my:replace-sequence">
>    <xsl:param name="source-string" as="xs:string" />
>    <xsl:param name="replace-spec" />
>
>
>
>    <xsl:variable name="replace-1" select="$replace-spec/replace[1]" />
>
>    <xsl:variable name="source-text" as="xs:string" select="
> $replace-1/@source" />
>    <xsl:variable name="replacement-text" as="xs:string" select="
> $replace-1/@replacement" />
>
>
>
>    <xsl:variable name="template-text-2" as="xs:string" select="replace(
> $source-string, $source-text, $replacement-text )" />
>
>
>
>    <xsl:variable name="replace-remainder"
> select="$replace-1/following-sibling::*" />
>
>
> On the first call your spec is a single document node with child element
children so
 $replace-spec/replace[1]

finds the first replacement.

But on later calls you pass $replace-1/following-sibling::*" which is a
sequence of replace elements so

$replace-spec/replace[1]

is empty.


Ypu want to write it always to take a sequence and selctt th first as

$replace-spec[1]

and of course pass a sequence in on the first call

David






>
>
>
>
> [image: Blue line]
>
> *Richard Kerry*
>
> BNCS Engineer, SI SOL Telco & Media Vertical Practice
>
> T: +44 (0)20 3618 2669
>
> M: +44 (0)7812 325518
>
> 4 Triton Square, Regentbs Place, London NW1 3HG
>
> richard.kerry@xxxxxxxx
>
<https://webmail.siemens-it-solutions.com/owa/redir.aspx?C=9fb20d019e3e4cb993
44d708709a3177&URL=mailto%3arichard.kerry%40atos.net>
>
>
>
> [image: Atos logo]
>
> This e-mail and the documents attached are confidential and intended
> solely for the addressee; it may also be privileged. If you receive this
> e-mail in error, please notify the sender immediately and destroy it. As
> its integrity cannot be secured on the Internet, the Atos group liability
> cannot be triggered for the message content. Although the sender endeavours
> to maintain a computer virus-free network, the sender does not warrant that
> this transmission is virus-free and will not be liable for any damages
> resulting from any virus transmitted.
>
Atos, Atos Consulting, Worldline and Canopy The Open Cloud Company are
> trading names used by the Atos group. The following trading entities are
> registered in England and Wales: Atos IT Services UK Limited (registered
> number 01245534), Atos Consulting Limited (registered number 04312380),
> Atos Worldline UK Limited (registered number 08514184) and Canopy The Open
> Cloud Company Limited (registration number 08011902). The registered office
> for each is at 4 Triton Square, Regentbs Place, London, NW1 3HG.The VAT
No.
> for each is: GB232327983.
>
> This e-mail and the documents attached are confidential and intended
> solely for the addressee, and may contain confidential or privileged
> information. If you receive this e-mail in error, you are not authorised to
> copy, disclose, use or retain it. Please notify the sender immediately and
> delete this email from your systems. As emails may be intercepted, amended
> or lost, they are not secure. Atos therefore can accept no liability for
> any errors or their content. Although Atos endeavours to maintain a
> virus-free network, we do not warrant that this transmission is virus-free
> and can accept no liability for any damages resulting from any virus
> transmitted. The risks are deemed to be accepted by everyone who
> communicates with Atos by email.
> XSL-List info and archive <http://www.mulberrytech.com/xsl/xsl-list>
> EasyUnsubscribe <-list/2739265> (by
> email <>)
>



--
http://dpcarlisle.blogspot.com/

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.