Problem with xsl:call-template

Discussion in 'XML' started by Remi COCULA, Dec 22, 2003.

  1. Remi COCULA

    Remi COCULA Guest

    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?
     
    Remi COCULA, Dec 22, 2003
    #1
    1. Advertising

  2. 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.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 |
    -----------------------
     
    Philippe Poulard, Dec 22, 2003
    #2
    1. Advertising

  3. "Remi COCULA" <> wrote in message
    news:bs6v9t$qfq$...
    > 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
     
    Dimitre Novatchev, Dec 22, 2003
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ray Tayek
    Replies:
    3
    Views:
    537
    Ray Tayek
    Nov 30, 2003
  2. Vijay singh
    Replies:
    1
    Views:
    453
    Martin Honnen
    Nov 4, 2004
  3. Replies:
    1
    Views:
    3,687
    A. Bolmarcich
    May 27, 2005
  4. lele1979

    xsl:Include e xsl:call-template

    lele1979, Nov 6, 2006, in forum: XML
    Replies:
    1
    Views:
    575
  5. lele1979

    xsl:Include e xsl:call-template

    lele1979, Nov 6, 2006, in forum: XML
    Replies:
    0
    Views:
    374
    lele1979
    Nov 6, 2006
Loading...

Share This Page