Closed Bug 546509 Opened 12 years ago Closed 12 years ago

with-param doesn't work with apply-templates


(Core :: XSLT, defect)

Not set





(Reporter: dfradin, Unassigned)



(2 files)

User-Agent:       Mozilla/5.0 (X11; U; Linux i686; en-US; rv: Gecko/20100106 Ubuntu/9.10 (karmic) Firefox/3.5.7
Build Identifier: Mozilla/5.0 (X11; U; Linux i686; en-US; rv: Gecko/20100106 Ubuntu/9.10 (karmic) Firefox/3.5.7

When trying to pass parameters, by using the element <xsl:with-param/>, to templates applied through the element <xsl:apply-templates>, said parameters' values are simply ignored by the templates involved, that systematically fall back to default values, if any.

Reproducible: Always

Steps to Reproduce:
1.Create a trivial XML file, with just a root element and a few children elements. Example:
<?xml version="1.0" encoding="UTF-8"?>

2.Create a XSLT sheet designed to turn the XML file into a HTML file with an unordered list containing as items the values of the children elements, using the apply-templates element to process the latter ones, with a parameter of which value will be appened to each of them, between parentheses.
Example :
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="">
  <xsl:output method="html"/>
  <xsl:template match="/">
        <title>trivial example</title>
    	  <xsl:apply-templates select="root">
	    <xsl:with-param name="thingy" select="'stuff'"/>
  <xsl:template match="child">
    <xsl:param name="thingy"/>
    <li><xsl:value-of select="."/>(<xsl:value-of select="$thingy"/>)</li>

3. Attach the stylesheet to the XML file with a proper <?xml-stylesheet?> declaration, then display the XML file in, for example, FireFox.
Actual Results:  
The browser displays the following:
    * item1()
    * item2()
    * item3()
    * item4()

Expected Results:  
    * item1(stuff)
    * item2(stuff)
    * item3(stuff)
    * item4(stuff)

This is a standard compliance issue, since the <xsl:apply-templates> element should be able to take parameters to transmit to its templates, as specified in the W3C recommendation for XSLT 1.0.:
I tested my example with xsltproc, which gave the expected result.

For information: there's no such issue with the <xsl:call-template> element, whith which parameters work quite fine.
Could you attach the testcase as a file. That will allow for much easier testing.
Attached file The target XML file
Attached file The XSLT sheet
Ah, I see the bug in the stylesheet now.

The <xsl:apply-templates> doesn't actually directly apply the template that accepts a parameter. You are trying to apply templates to the <root> element. However there is no template in your stylesheet that applies to the <root> element. Thus a default template is applied. This default template applies templates to all children, however it does not forward any parameters.

This is all per spec.

If you change it to <xsl:apply-templates select="root/child"> then it should work.
Closed: 12 years ago
Resolution: --- → INVALID
You need to log in before you can comment on or make changes to this bug.