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“).
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> [...]