XPath

by

Requirements

This task requires Xalan 2.x and a JAXP compliant parser.

Description

Invokes the Xalan XPath API over an XML document and replace specified node values by new values.

Parameters

Attribute Description Required
file The XML file to which the Audit result should be written to. Yes
tofile The XML file resulting from the XPath modifications. No (default is to modify the source file)
select The XPath expression that select nodes to process. No. (Yes if select is set)
value The value to replace  No. (Yes if select is set)

Nested elements

apply

An XPath expression to apply on the XML document.

Attribute Description Required
select The XPath expression that select nodes to process. Yes.
value The value to replace  Yes.

Note that XPath expressions will be evaluated in the order they are declared. The one declared as attributes of xpath being the first one (if declared).

Example

  <xpath file="./xml/input.xml" tofile="./xml/output.xml">
      <apply select="/root/nodea/@attr1" value="newvalue1"/>
      <apply select="/root/nodeb/@attr5" value="newvalue5"/>
  </xpath>

This invokes XPath and replace the value of the selected attributes by respectively newvalue1 and newvalue5, as indicated below:

Before After
  <root>
    <nodea attr1="oldvalue1"/>
    <nodea attr1="oldvalue1"/>
    <nodeb attr5="oldvalue5"/>
  </root>
  <root>
    <nodea attr1="newvalue1"/>
    <nodea attr1="newvalue1"/>
    <nodeb attr5="newvalue5"/>
  </root>