Reputation: 13940
The XSLT1 spec, xsl:import
section is not very clear/direct about things like:
output
tag, what will be used?xmlns:xsl
) or other global (ex. exclude-result-prefixes
), what will be used globally?I have a "hub XSLT" with all attributes and global tags... But now I am importing some XSLTs that are also standalone XSLTs, so perhaps in the future I will notice surprises... To avoid surprises, this question.
Summarizing the question:
Can all the XSLTs be "empty of gobal tags" if the "hub XSLT" has all of them? If there is conflict, what are the precedence rules?
Upvotes: 2
Views: 150
Reputation: 22637
You are asking if it is sufficient to have all the declarations only in the importing module, but at the same time you are saying that all modules are also "standalone" XSLT stylesheets? Makes no sense to me. Obviously, an imported module would not be a full-flegded stylesheet anymore if it did not have declarations and, in the case of missing namespace declarations, it would not be well-formed XML anymore. And a stylesheet that is malformed XML would be utterly useless.
In general, imported declarations (declarations that physically reside in the imported stylesheet module) have a lower precedence. But some qualifications are needed.
xsl:output/@method
xsl:output
is a declaration, if there is conflict between stylesheets, the importing module takes precedence over the imported one. Consequently, the output method declared in the importing stylesheet will be used. But a caveat here: not all attributes of xsl:output
are treated in the same way.
Namespaces
Namespaces (and thus prefixes) that are defined in the importing stylesheet are not available in the imported stylesheet. This means that if you define
xmlns:ns="www.namespace.com"
in the importing stylesheet, the prefix ns
will not be connected to the namespace URI "www.namespace.com"
in the imported module. In such a case, you need to redeclare the namespace.
And if you ponder this fact for a while, it becomes obvious why this is so: A stylesheet (module) does not need to be imported. It should always be possible to use it on its own or import it. The only way to make sure a stylesheet retains its independence is to declare all namespaces in it.
exclude-result-prefixes
For attributes like exclude-result-prefixes
I quote Michael Kay1, saying that
[t]he values of the
version
,extension-element-prefixes
,exclude-result-prefixes
andxpath-default-namespace
attributes that apply to an element in the imported stylesheet, as well asxml:lang
andxml:space
, are those that were defined in the<xsl:stylesheet>
element of their own module, not those on the<xsl:stylesheet>
element of the importing module.
The easiest way to find the rules would of course be to simply test. In most cases, the test would be a pretty trivial one. For example, define two output methods in the stylesheet modules:
<xsl:output method="text"/> <xsl:output method="xml"/>
and see if the output is text or XML.
And that's exactly how you should go about finding the rules for "...etc..." from your question.
1 Michael Kay, XSLT 2.0 and XPath 2.0 Programmer's Reference, p. 358
Upvotes: 2