Problem with xsl:call-template

R

Remi COCULA

When using xsl:call-template it seems that we can't use a parameter as the
name of the template to call.
Example :

<xsl:template name="cadre">
<xsl:param name="p_contenu"/>

<xsl:call-template name="{$p_contenu}"/>
</xsl:template>

It does'nt work : Xalan logs this error (sorry it's french)

2003-12-22 03:16:28 - path="/gcdev" :gc:
javax.xml.transform.TransformerConfigurationException:
javax.xml.transform.TransformerException:
javax.xml.transform.TransformerException: Valeur incorrecte : {$p_contenu}
utilisée pour l'attribut QNAME : name

Any suggestion to fix this problem?
 
P

Philippe Poulard

Remi said:
When using xsl:call-template it seems that we can't use a parameter as the
name of the template to call.
Example :

<xsl:template name="cadre">
<xsl:param name="p_contenu"/>

<xsl:call-template name="{$p_contenu}"/>
</xsl:template>

It does'nt work : Xalan logs this error (sorry it's french)

2003-12-22 03:16:28 - path="/gcdev" :gc:
javax.xml.transform.TransformerConfigurationException:
javax.xml.transform.TransformerException:
javax.xml.transform.TransformerException: Valeur incorrecte : {$p_contenu}
utilisée pour l'attribut QNAME : name

Any suggestion to fix this problem?

hi,

this is not an error : the name of a template *must* be a QName, as
xalan output shows

however, you may use the following design pattern, known as "template
tag" to get the requested behaviour :

<xsl:stylesheet xmlns:xsl="..."
xmlns:tt="*** template tag ***">

....

<xsl:template name="cadre">
<xsl:param name="p_contenu"/>
<xsl:apply-templates
select="document('')/*/tt:template[@name=$p_contenu]"/>
</xsl:template>

<tt:template name="theName"/>
<xsl:template match="tt:template[@name='theName']">
<!--your stuff here-->
</xsl:template>

<tt:template name="anotherName"/>
<xsl:template match="tt:template[@name='anotherName']">
<!--your stuff here-->
</xsl:template>

--
Cordialement,

///
(. .)
-----ooO--(_)--Ooo-----
| Philippe Poulard |
-----------------------
 
D

Dimitre Novatchev

Remi COCULA said:
When using xsl:call-template it seems that we can't use a parameter as the
name of the template to call.

This cannot be done with xsl:call-template, because the Spec requires the
value of its "select" attribute to be a QName, which, among other things by
definition, must be statically known (at compile time).


What you want to achieve is done by using the general XSLT design pattern of
"generic templates" or "template references".

For more information read the first article on the home page of FXSL -- the
functional programming library for XSLT.

See also my presentation "Functional programming in XSLT using the FXSL
library" delivered at this year's "Extreme Markup Languages" conference:

http://www.idealliance.org/papers/extreme03/xslfo-pdf/2003/Novatchev01/EML2003Novatchev01.pdf




Dimitre Novatchev.
FXSL developer, XML Insider,

http://fxsl.sourceforge.net/ -- the home of FXSL
Resume: http://fxsl.sf.net/DNovatchev/Resume/Res.html
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top