[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: "Kerry, Richard richard.kerry@xxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Thu, 17 Dec 2015 12:31:11 -0000
Re:  Recursion not recursing
-----Original Message-----
From: Martin Honnen martin.honnen@xxxxxx
[mailto:xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx]
Sent: Thursday, December 17, 2015 12:15 PM
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: Re:  Recursion not recursing, or not passing parameter. Multiple
search/ replace.

Kerry, Richard richard.kerry@xxxxxxxx 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>

Here your variable is a tree fragment with three `replace` child elements.


>     <xsl:variable name="replace-1" select="$replace-spec/replace[1]"
> />

Here you select the first child element.

>     <xsl:variable name="source-text" as="xs:string"
> select="$replace-1/@source <mailto:$replace-1/@source>" />
>     <xsl:variable name="replacement-text" as="xs:string"
> select="$replace-1/@replacement <mailto:$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::*" />

Here you select the two following sibling elements

>     <xsl:choose>
>       <xsl:when test="$replace-remainder" >
>          <xsl:variable name="template-text-3"
> as="xs:string" select="my:replace-sequence( $template-text-2,
> $replace-remainder )" />

and pass them on, which means in the recursive call you are trying to select
the replace[1] child of those siblings, and they don't have children.

So you rather want to set up the variable as

   <xsl:variable name="replace-spec"
as="element(replace)*">...</xsl:variable>

then in the function select

   <xsl:variable name="replace-1" select="$replace-spec[1]" />

and further on

  <xsl:variable name="replace-remainder"
select="$replace-spec[position() gt 1]" />

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.