Undeclared params

Phil Shafer <[email protected]>
Newsgroups gmane.comp.gnome.lib.xslt
Message-ID <[email protected]>
Is an <xsl:param> statement required for all global variables?
xsltproc will happily allow a reference to an undeclared param _if_
the param has a value passed in.   I noticed today that a customer's
script was depending on this behavior, which I thought would be an
error.

In this example the variable "test" is not declared.  Running
xsltproc without a "--param test" gives an error but with a "--param
test" it runs fine.

% cat test.xsl
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
  <xsl:template match="/">
    <out>
      <value>
        <xsl:value-of select="concat(&quot;test: &quot;, $test)"/>
      </value>
    </out>
  </xsl:template>
</xsl:stylesheet>
% xsltproc test.xsl test.xml
runtime error: file test.xsl line 6 element value-of
Variable 'test' has not been declared.
xmlXPathCompOpEval: parameter error
runtime error: file test.xsl line 6 element value-of
XPath evaluation returned no result.
<?xml version="1.0"?>
<out><value/></out>
% xsltproc --param test '"test"' test.xsl test.xml
<?xml version="1.0"?>
<out><value>test: test</value></out>
% 

Thanks,
 Phil
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.