MacOS comes with a command line Xpath evaluator (useful!):

$ xpath inputfile.xml '//ws:Worker[ws:Personal/ws:Email_Data[ws:Email_Type="HOME" and ws:Is_Primary!="true"]'

Quick and dirty way of finding the number of occurrences of an XML element:

$ grep -o '<ws:Worker>' inputfile.xml | wc -l



document() can be used to access nodes in an external XML document:


Path resolution

When using Apache Camel’s XSLT component, the path argument can be:

  • filename.xml - this will look in the classpath (relative to the location of the XSLT file)
  • file:///home/jsmith/files/filename.xml - this will look on the file system at the given location

Example - using document() with a mapping file

Given an XML document like this:

<?xml version="1.0" encoding="UTF-8"?>
    <customerTypeMapping source="Basic" target="B"/>
    <customerTypeMapping source="Premium" target="P"/>
    <customerTypeMapping source="Gold" target="G"/>

You can implement XSLT like this to read in the document and then use the data within a template - e.g. to map one value to another:

<xsl:param name="myXmlDocument"/>
<xsl:variable name="my_variable"
<xsl:template match="ns1:Customer_Type">
    <xsl:value-of select="$my_variable/customerTypeMappings/customerTypeMapping[@source = current()]/@target"/>