Connecting Tech Pros Worldwide Help | Site Map

Problem with xsl:call-template

Remi COCULA
Guest
 
Posts: n/a
#1: Jul 20 '05
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?







Philippe Poulard
Guest
 
Posts: n/a
#2: Jul 20 '05

re: Problem with xsl:call-template


Remi COCULA wrote:[color=blue]
> 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?
>[/color]

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 |
-----------------------

Dimitre Novatchev
Guest
 
Posts: n/a
#3: Jul 20 '05

re: Problem with xsl:call-template



"Remi COCULA" <remi.cocula@wanadoo.fr> wrote in message
news:bs6v9t$qfq$1@news-reader5.wanadoo.fr...[color=blue]
> When using xsl:call-template it seems that we can't use a parameter as the
> name of the template to call.[/color]

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


Closed Thread