Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > Variable name for call-template

Reply
Thread Tools

Variable name for call-template

 
 
Julien Phalip
Guest
Posts: n/a
 
      08-11-2004
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
 
Reply With Quote
 
 
 
 
Marrow
Guest
Posts: n/a
 
      08-11-2004
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) om...
> 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



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
"Variable variable name" or "variable lvalue" mfglinux Python 11 09-12-2007 03:08 AM
adding a variable name to a hash to name is part of the variable name Bobby Chamness Perl 2 04-22-2007 09:54 PM
print("my name is {name}, and {age}-year old {gender}", name, age, gender); =?iso-8859-1?B?bW9vcJk=?= Java 7 01-02-2006 04:39 PM
How do I scope a variable if the variable name contains a variable? David Filmer Perl Misc 19 05-21-2004 03:55 PM
Re: Urgent! how to get object name, method name and attribute name based on the strings? ding feng C++ 2 06-25-2003 01:18 PM



Advertisments