Is it possible to assign a value to a parameter of an imported stylesheet?
I was expecting something like
<xsl:import ... >
<xsl:with-param ...
</xsl:import>
but that is not allowed.
Also tunnel="yes" is forbidden in stylesheet parameters.
Is it possible to assign a value to a parameter of an imported stylesheet?
I was expecting something like
<xsl:import ... >
<xsl:with-param ...
</xsl:import>
but that is not allowed.
Also tunnel="yes" is forbidden in stylesheet parameters.
A quick glance at the specs shows that no such construct is permitted:
In short,
href
is the only allowed attribute and there is no content allowed in the element's body.However, if I understand your use case, then you should simply set the parameter in the normal way (using your host language). It shouldn't really matter that it was defined in the imported stylesheet. For example, assume you have this stylesheet:
Which imports this:
...then setting the
test
parameter in the normal way should just work. Note that you can also "mask" the parameter from the imported sheet if you want to provide a new default value.So, adding this to the first stylesheet:
...would cause it to print
default2
(overriding the default from the imported sheet).Try this:
main.xsl
import.xsl
An xsl:variable in an importing stylesheet can override an xsl:param in an imported stylesheet, and this effectively sets the value of the parameter.
Just to add to lwburk's excellent answer (+1), here's one more example of assigning a value to a parameter in an imported stylesheet.
You wouldn't need to add
xsl:param
to the main stylesheet; you would just assign the value when you called the stylesheet (on the command line for example).main.xsl
import.xsl
example saxon command line (setting new parameter value)
output.xml
Maybe this is also helpful:
In XSLT 2.0 one can pass parameters to an overriden template in an imported stylesheet and instantiate it from the overriding template using:
<xsl:apply-imports>
.Passing parameters with
<xsl:apply-imports>
is a feature only of XSLT 2.0 -- this isn't possible in XSLT 1.0.