XPath can only select nodes, it cannot write to a file.
In XPath 1.0 there is no standard way to reference in a single expression nodes belonging to more than one XML document. If the programming language that is hosting XPath is XSLT, then the document nodes of the three XML documents can be in three separate xsl:variable
s: $doc1
, $doc2
and $doc3
.
$doc1//whoopdee | $doc2//whoopdee | $doc3//whoopdee
Alternatively, the XSLT document()
function can be used directly:
document('file1.xml')//whoopdee
| document('file2.xml')//whoopdee
| document('file3.xml')//whoopdee
To output the result of either XPath expressions above, using XSLT one would simply write:
<xsl:copy-of select="$doc1//whoopdee | $doc2//whoopdee | $doc3//whoopdee">
or
<xsl:copy-of select=
"document('file1.xml')//whoopdee
| document('file2.xml')//whoopdee
| document('file3.xml')//whoopdee
">
In XPath 2.0 one can use the standard doc()
function and will not depend on the host of XPath.
Command-line:
One can use any XSLT processor, which allows command line instantiation. Most XSLT processors do allow this. They also allow simple parameters to be passed in the command line -- usually in the format name=value
. Finally, most XSLT processors allow the destination file for the result to be specified as an option. Here is a link to the Saxon documentation of its command-line usage:
http://www.saxonica.com/documentation/using-xsl/commandline.html