Reputation: 23
We are upgrading saxon 9.3.0.2 to saxon ee-9.5.1.8 after the upgrade is finised we get's alot of warning's
net.sf.saxon.trans.XPathException: The source document is in namespace [MY-NAME-SPACE] , but none of the template rules match elements in this namespace
at net.sf.saxon.Controller.warning(Controller.java:954)
at net.sf.saxon.Controller.transformDocument(Controller.java:2081)
at net.sf.saxon.Controller.transform(Controller.java:1911)
I removed the namespace from the xsl and i still get this warning Anyone know's what's going on ? How to remove this warning ?
Upvotes: 2
Views: 1204
Reputation: 163498
The first thing to do is to establish whether the warning is a false alarm.
The warning was added to Saxon because of the large number of people making the same mistake (about one a day ask the question on StackOverflow, so heaven only knows how many are suffering silently). In particular, the mistake is to have a source document like this:
<foo xmlns="http://default.namespace.com/">
<bar/>
<baz/>
</foo>
and then to write match patterns like
<xsl:template match="foo"/>
<xsl:template match="bar"/>
which will never match anything because they ignore the namespace.
So what Saxon does is this: if
(a) the outermost element of the source document is in a namespace
(b) there are template rules in the stylesheet that match specific element names
(c) there's no intersection between the namespaces of elements that are matched by the stylesheet and the namespaces that actually occur in the source document
then it outputs this warning.
If it really is a false alarm, there are a couple of ways you can suppress it:
(a) add a dummy template rule to your stylesheet, perhaps with a predicate that means it will never match anything, but which uses the namespace of the source document, just to tell the processor you know what you're doing.
(b) set the configuration property FeatureKeys.SUPPRESS_XSLT_NAMESPACE_CHECK
, which can do from within the API like this:
import net.sf.saxon.s9api.Processor;
import net.sf.saxon.s9api.XsltCompiler;
Processor processor = new Processor(configuration);
processor.setConfigurationProperty(FeatureKeys.SUPPRESS_XSLT_NAMESPACE_CHECK, "true");
XsltCompiler xsltCompiler = processor.newXsltCompiler();
or from the command line by adding --suppressXsltNamespaceCheck:on
.
It it is a false alarm, I would love to see the details so that we can refine the checking. We do know that there are cases where the conditions can occur quite legitimately, for example when your initial source document is a simple list of files to be processed, and all the real work of the stylesheet is in processing those files; but we thought it worth having a small number of false alarms to save beginners the frustration of solving this simple and common problem.
Upvotes: 2