By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,750 Members | 2,061 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,750 IT Pros & Developers. It's quick & easy.

XSLT: Using attribute value templates in xsl:element

P: n/a
Hi there.

I want to generate elements, choosing the element name dynamically. So I
tried to use attribute value templates:

<xsl:element name="{$local-name($someNode)}">
<!-- Generate element content. -->

where $someNode is an XML tree.

This doesn't work: the xslt processor sees the attribute value template
as an illegal qname. However, when I print out this value using
xsl:value-of, it appears to be perfectly valid.

So I changed the first line into

<xsl:element name="p{$local-name($someNode)}">

(notice the extra 'p' before the avt)
This works (strangely enough to me), but is of course useless as I don't
want that extra 'p'. I get the same behavior in Saxon b8.6.1, Xalan J
2.7.0 and Msxsl 4.0.

I know there are work-arounds to get the result that I want, but does
anybody know why the first version doesn't work and the second does?

Thanks in advance.

Filip Hendrickx.
Feb 8 '06 #1
Share this Question
Share on Google+
1 Reply

P: n/a
Hi Filip,

You have an extra $ in your AVT thus making the processor look for a
variable or parameter with the name local while what you want is the
local-name function. Here it is a sample stylesheet with that corrected
that works ok:

<xsl:stylesheet version="1.0"
<xsl:param name="someNode" select="/*"/>
<xsl:template match="/">
<xsl:element name="{local-name($someNode)}">
<!-- Generate element content. -->

Best Regards,
George Cristian Bina
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger

Feb 9 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.