[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

[xsl] Recursion not recursing, or not passing parameter. Multiple search/ replace.


Subject: [xsl] 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 11:56:14 -0000

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<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::*" />

   <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 )" />
        <xsl:value-of select="$template-text-3" />
     </xsl:when>
     <xsl:otherwise>
        <xsl:value-of select="$template-text-2" />
     </xsl:otherwise>
   </xsl:choose>
</xsl:function>

I've used a few xsl:message calls to see what the size of the sequence is at
various points, and to confirm that the recursion call is being done.
However, having checked that the size of replace-remainder is two before the
call, as soon as it re-enters my:replace-sequence the size has become zero.



Can anyone advise what I may be doing wrong.



Regards,

Richard.








[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, Regents Place, London NW1 3HG
richard.kerry@xxxxxxxx<https://webmail.siemens-it-solutions.com/owa/redir.asp
x?C=9fb20d019e3e4cb99344d708709a3177&URL=mailto%3arichard.kerry%40atos.net>

[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, Regents 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.


Current Thread
Keywords