Variable name for call-template

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Julien Phalip

    #1

    Variable name for call-template

    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

    #2
    Re: Variable name for call-template

    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="attribu te"/>
    </xsl:template>

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

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

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


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



    "Julien Phalip" <allezlisle@yah oo.fr> wrote in message
    news:65001b61.0 408102210.7cce2 dcb@posting.goo gle.com...[color=blue]
    > 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[/color]


    Comment

    Working...