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

Subject: RE: [xsl] 'apply-templates' on parameter of 'call-template'
From: "Michael Kay" <mhk@xxxxxxxxx>
Date: Fri, 9 Apr 2004 20:02:30 +0100
This isn't legal under XSLT 1.0, it violates the restrictions on result tree
fragments that the xx:node-set() extension was designed to circumvent.

Because Saxon 6.x implemented XSLT 1.1, which dropped these restrictions,
and then back-pedalled when XSLT 1.1 was withdrawn, its behavior is actually
a little inconsistent: it doesn't always raise errors when you use RTFs in
ways that XSLT 1.0 doesn't allow.

An XSLT 2.0 processor, given this stylesheet, will go into infinite
recursion, because the template rule that matches the $body variable is the
match="/" template. I assume when you say the processor "blows up" that this
is what is happening.

Michael Kay 

> -----Original Message-----
> From: Angus McIntyre [mailto:angus@xxxxxxxxx] 
> Sent: 09 April 2004 17:08
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject: [xsl] 'apply-templates' on parameter of 'call-template'
> 
> 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:with-param>
> 	   </xsl:call-template>
> 	</xsl:template>
> 
> 	<xsl:template name="test">
> 	   <xsl:param name="body">no body</xsl:param>
> 	   <xsl:apply-templates select="$body"/>
> 	</xsl:template>
> 
> 	<xsl:template name="matchable">
> 	   <p>The value is <xsl:value-of select="@id"/></p>
> 	</xsl:template>
> 
> 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,
> 
> Angus
> -- 
> Business:   http://www.nomadcode.com/
> Personal:   http://www.raingod.com/angus/
> Political:  http://www.gollum2004.com/

Current Thread