[xsl] 'apply-templates' on parameter of 'call-template'

Subject: [xsl] 'apply-templates' on parameter of 'call-template'
From: Angus McIntyre <angus@xxxxxxxxx>
Date: Fri, 9 Apr 2004 13:07:37 -0400
Is it legitimate to invoke 'xsl:apply-templates' on a parameter passed to 'xsl:call-template'? In other words, should the following fragment be expected to work:

	<xsl:template match="/">
	   <xsl:call-template name="test">
	      <xsl:with-param name="body">
	         <p>This is my body</p>
	         <matchable id="123"/>

	<xsl:template name="test">
	   <xsl:param name="body">no body</xsl:param>
	   <xsl:apply-templates select="$body"/>

	<xsl:template name="matchable">
	   <p>The value is <xsl:value-of select="@id"/></p>

On the test platform I'm using (TestXSLT from Marc Liyanage), the different stylesheet processors all choke on this in different ways. Xalan throws an error, LibXSLT ignores it, Saxon and Sablotron blow up.

Replacing the 'xsl:apply-templates' in the named template 'test' by 'xsl:copy-of' works fine - except that, of course, the "matchable" template is never invoked.

The Xalan error ("can not convert #RTREEFRAG to a nodelist") hints that I'm trying to do something basically contrary to the spirit of XSL, or at least XSL 1.0. What I'd like to do can be described as follows: use 'call-template' to 'surround' an arbitrary block of XML, _contained in the XSL stylesheet_, by additional XML content - and have templates applied to the contained block in the usual way.

As to why I want to do this particularly horrible thing, put it down to someone else's questionable design decisions. If the nodes that I want to 'surround' were in the XML rather than the XSL, this would be trivial.

Thanks in advance for any suggestions,

Business:   http://www.nomadcode.com/
Personal:   http://www.raingod.com/angus/
Political:  http://www.gollum2004.com/

Current Thread