XProc steps

A | B | C | D | E | F | G | H | I | J | K | L | M | N | O | P | Q | R | S | T | U | V | W | X | Y | Z

p:string-replace

<p:declare-step type="p:string-replace">
   <p:input port="source"/>
   <p:output port="result"/>
   <p:option name="match" required="true"/> <!-- XSLTMatchPattern -->
   <p:option name="replace" required="true"/> <!-- XPathExpression -->
</p:declare-step>

With the help of the <p:string-replace> step, strings can be replaced. On the basis of a XSLT expression which is indicated in the “match“ option, the appropriate target is replaced by a new string which is deposited in the “replace“ option as XPath expression. The initial document is indicated at the input port (“source“). The result is written on the ouput port (“result“).

Example

In the following example all "LeadingActor" entries with the value “Mark Hamill“ shall be replaced by “Harrison Ford“.

<?xml version="1.0" encoding="UTF-8"?>
<p:declare-step xmlns:p="http://www.w3.org/ns/xproc" xmlns:c="http://www.w3.org/ns/xproc-step" version="1.0">
   <p:input port="source">
      <p:document href="FilmCollection.xml"/>
   </p:input>
   <p:output port="result"/>
   <p:string-replace match="/FilmCollection/Film/Cast/LeadingActor[text()='Mark Hamill']" replace="/FilmCollection/Film/Cast/LeadingActor[text()='Harrison Ford']"/>
</p:declare-step>

After the execution of this stylesheet, all “LeadingActor“ elements with the value “Mark Hamill“ are replaced by “Harrison Ford“ in the output. But without markup tags since XPath only addresses the value of the specific element. The result would be as follows (excerpt):

[...]
  <Cast>
     Harrison Ford
     <LeadingActor>Harrison Ford</LeadingActor>
  </Cast>
[...]