By default, unprefixed element names in XPath expressions refer to elements with no namespace, thus an expression EventDocument
selects elements with local name "EventDocument" and no namespace. The
<EventDocument ... xmlns="http://www.itron.com/ItronInternalXsd/1.0/">
element does not match this pattern, as it is in the http://www.itron.com/ItronInternalXsd/1.0/
namespace.
You have two choices, either
- bind that namespace to a prefix in the stylesheet, then use the prefix in the XPath expression, or
- (since you say you are in XSLT 2.0) use
xpath-default-namespace
Example of 1
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:itron="http://www.itron.com/ItronInternalXsd/1.0/"
version="2.0">
<xsl:template match="itron:example">
<xsl:if test="itron:EventDocument">....</xsl:if>
</xsl:template>
</xsl:stylesheet>
Example of 2
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xpath-default-namespace="http://www.itron.com/ItronInternalXsd/1.0/"
version="2.0">
<xsl:template match="example">
<xsl:if test="EventDocument">....</xsl:if>
</xsl:template>
</xsl:stylesheet>
My personal preference is for option 1, on the "principle of least surprise" basis for anyone who has to maintain the stylesheet in future (including the original author, coming back to the code after a few months break...).