Using XSLT to convert adhoc element name to attribute name

M

Moonbeam66

I'm looking to convert an element name to an attribute name, where the
element name is user-defined. For example
<accountNumber>12345678</accountNumber>. I want to convert this to
<userTag name="accountNumber">12345678</userTag>. Where I'm having
probs is getting the element name to appear as the value for the
attribute in the transformed XML. Any ideas?

If I use the following XSL

<xsl:attribute name="name">
name()
</xsl:attribute>

I get the following result:

<userTag name="name()"> .. </userTag>

I get the same sort of result if I just use "." instead of "name()".

Thanks
 
R

Richard Tobin

<xsl:attribute name="name">
name()
</xsl:attribute>

<xsl:attribute name="name">
<xsl:value-of select="name()"/>
</xsl:attribute>

or if you are using a literal result element use an attribute
value template:

<userTag name="{name()}">

-- Richard
 

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

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top