By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,588 Members | 1,937 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,588 IT Pros & Developers. It's quick & easy.

Problem with xsl:call-template

P: n/a
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.TransformerConfigurationExcept ion:
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?



Jul 20 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Remi COCULA wrote:
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.TransformerConfigurationExcept ion:
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 |
-----------------------

Jul 20 '05 #2

P: n/a

"Remi COCULA" <re*********@wanadoo.fr> wrote in message
news:bs**********@news-reader5.wanadoo.fr...
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/ex...ovatchev01.pdf


Dimitre Novatchev.
FXSL developer, XML Insider,

http://fxsl.sourceforge.net/ -- the home of FXSL
Resume: http://fxsl.sf.net/DNovatchev/Resume/Res.html
Jul 20 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.