[prev in list] [next in list] [prev in thread] [next in thread] 

List:       xsl-list
Subject:    Re: [xsl] Recursion not recursing, or not passing parameter. Multiple search/ replace.
From:       "Kerry, Richard richard.kerry () atos ! net" <xsl-list-service () lists ! mulberrytech ! com
Date:       2015-12-17 12:31:45
Message-ID: 20151217073110.81675 () lists ! mulberrytech ! com
[Download RAW message or body]


-----Original Message-----
From: Martin Honnen martin.honnen@gmx.de \
                [mailto:xsl-list-service@lists.mulberrytech.com]
Sent: Thursday, December 17, 2015 12:15 PM
To: xsl-list@lists.mulberrytech.com
Subject: Re: [xsl] Recursion not recursing, or not passing parameter. Multiple \
search/ replace.

Kerry, Richard richard.kerry@atos.net 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]" />

--~----------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
EasyUnsubscribe: -list/2528992
or by email: 
--~-
[R>]
[R>]
[R>] Excellent.
Thank you very much Martin, that seems to have done the job.
I'd already spent a bit of time getting the replacements sequence working well enough \
to get the first replacement done, but had obviously missed the details of structure \
that you spotted.

Regards,
Richard.



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, Regent's 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: http://lists.mulberrytech.com/unsub/xsl-list/651070
or by email: xsl-list-unsub@lists.mulberrytech.com
--~--


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic