Variable name for call-template

J

Julien Phalip

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
 
M

Marrow

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,048
Latest member
verona

Latest Threads

Top