GNOME Bugzilla – Bug 307061
global parameters can be referenced without xsl:param declaration
Last modified: 2021-07-05 10:59:25 UTC
In PHP, I'm passing external XSL parameters directly to the libxslt processor like so: $xslt_proc->setParameter('', 'param_test', "some test value"); *Without* having a global xsl:param definition in the xsl stylesheet, the following works without errors: <xsl:value-of select="$param_test"/> Based on the xsl spec, shouldn't this reference to the undefined global parameter fail?
I can't find a passage in the spec, which mandates an error/warning to be raised here. Relevant spec pieces: 11.4 Top-level Variables and Parameters: "XSLT does not define the mechanism by which parameters are passed to the stylesheet" If the passing of parameters via the API is comparable to xsl:with-param, then I would not expect an error/warning to be raised; in "11.6 Passing Parameters to Templates" we have: "It is not an error to pass a parameter x to a template that does not have an xsl:param element for x; the parameter is simply ignored."
I now think that you are right: although an externally given parameter, which is not declared globally in the stylesheet should not produce an error, but the actual usage, or the mere reference to a non-declared param/var should produce an error. The processor doesn't check for the existence of vars/params used in XPath expressions yet at compile time. Is the XPath machinery able to give us a way of validating variable references at stylesheet-compilation time?
Not really. This would need another API taking a compiled XPath expression and returning the list of namespace/name for variables names. This is one of the limitiations of a separated XPath engine, if it was embedded in libxslt thenat compilation time the XPath would call the XSLT saying 'reference to variable foo' and then the XSLT would precompute the slot in teh variable stack associated to 'foo' and return the index. As a result at runtime they would be no lookup for variable, the index would be known immediately. Daniel
GNOME is going to shut down bugzilla.gnome.org in favor of gitlab.gnome.org. As part of that, we are mass-closing older open tickets in bugzilla.gnome.org which have not seen updates for a longer time (resources are unfortunately quite limited so not every ticket can get handled). If you can still reproduce the situation described in this ticket in a recent and supported software version, then please follow https://wiki.gnome.org/GettingInTouch/BugReportingGuidelines and create a new ticket at https://gitlab.gnome.org/GNOME/libxslt/-/issues/ Thank you for your understanding and your help.