XPath can only select nodes; it cannot write to a file.
In XPath 1.0, there is no standard way to refer to a single expression node that belongs to more than one XML document. If the programming language that hosts XPath is XSLT, then document nodes from three XML documents can be in three separate xsl:variable s: $doc1 , $doc2 and $doc3 .
$doc1//whoopdee | $doc2//whoopdee | $doc3//whoopdee
Alternatively, the XSLT function document() can be used directly:
document('file1.xml')//whoopdee | document('file2.xml')//whoopdee | document('file3.xml')//whoopdee
To output the result of XPath expressions above using XSLT, 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, you can use the standard doc() function and will not depend on the XPath host.
Command line
You can use any XSLT processor that allows you to instantiate a command line. Most XSLT processors allow this. They also allow you to pass simple parameters on the command line - usually in the format name=value . Finally, most XSLT processors allow you to specify the target file for the result as an option. Here is a link to the Saxon documentation for using it on the command line:
http://www.saxonica.com/documentation/using-xsl/commandline.html
source share