Variable name for call-template

Discussion in 'XML' started by Julien Phalip, Aug 11, 2004.

  1. Hi everyone!

    I am trying to do a transformation from the xml file:

    <foo>
    <attribute>a</attribute>
    ...
    </foo>

    The xsl file is as follows:

    <xsl:template name="foo">
    <xsl:if test="attribute = 'a'">
    <xsl:call-template name="a"/>
    </xsl:if>
    <xsl:if test="attribute = 'b'">
    <xsl:call-template name="b"/>
    </xsl:if>
    <xsl:if test="attribute = 'c'">
    <xsl:call-template name="c"/>
    </xsl:if>
    </xsl:template>

    I would like to make the xsl file simpler with something like:
    <xsl:template name="foo">
    <xsl:call-template name="{./attribute}"/>
    </xsl:template>

    But I got an error saying: "Could not find template named: {./attribute}"

    Can anyboby help me with that?

    Thanks a lot!

    Julien Phalip
     
    Julien Phalip, Aug 11, 2004
    #1
    1. Advertising

  2. Julien Phalip

    Marrow Guest

    Hi Julien,

    Can't you just use apply-templates and rather than have named templates use
    template matching? Something like...

    <xsl:template name="foo">
    <xsl:apply-templates select="attribute"/>
    </xsl:template>

    <xsl:template match="attribute[. = 'a']">
    ...
    </xsl:template>

    <xsl:template match="attribute[. = 'b']">
    ...
    </xsl:template>

    <xsl:template match="attribute[. = 'c']">
    ...
    </xsl:template>


    Cheers
    Marrow
    http://www.marrowsoft.com - home of Xselerator (XSLT IDE and debugger)
    http://www.topxml.com/Xselerator



    "Julien Phalip" <> wrote in message
    news:...
    > Hi everyone!
    >
    > I am trying to do a transformation from the xml file:
    >
    > <foo>
    > <attribute>a</attribute>
    > ...
    > </foo>
    >
    > The xsl file is as follows:
    >
    > <xsl:template name="foo">
    > <xsl:if test="attribute = 'a'">
    > <xsl:call-template name="a"/>
    > </xsl:if>
    > <xsl:if test="attribute = 'b'">
    > <xsl:call-template name="b"/>
    > </xsl:if>
    > <xsl:if test="attribute = 'c'">
    > <xsl:call-template name="c"/>
    > </xsl:if>
    > </xsl:template>
    >
    > I would like to make the xsl file simpler with something like:
    > <xsl:template name="foo">
    > <xsl:call-template name="{./attribute}"/>
    > </xsl:template>
    >
    > But I got an error saying: "Could not find template named: {./attribute}"
    >
    > Can anyboby help me with that?
    >
    > Thanks a lot!
    >
    > Julien Phalip
     
    Marrow, Aug 11, 2004
    #2
    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. =?iso-8859-1?B?bW9vcJk=?=
    Replies:
    7
    Views:
    857
    Roedy Green
    Jan 2, 2006
  2. ding feng
    Replies:
    2
    Views:
    2,849
    ding feng
    Jun 25, 2003
  3. Bobby Chamness
    Replies:
    2
    Views:
    2,415
    Joe Smith
    Apr 22, 2007
  4. mfglinux
    Replies:
    11
    Views:
    724
    Roberto Bonvallet
    Sep 12, 2007
  5. David Filmer
    Replies:
    19
    Views:
    256
    Kevin Collins
    May 21, 2004
Loading...

Share This Page