XSLT Newbie: Attribute Value transformed to Attribute Name

B

bprimuslevy

I have an XML Document that looks like this...
<UserPermission>
<Permission Desc="DoSomething" Assigned="1" />
<Permission Desc="CanAlsoDo" Assigned="1"/>
</UserPermission>

I would like to transform the document to look like this...

<User Permission>
<Permission DoSomething="1" CanAlsoDo="1"/>
</UserPermission>

This is my xslt snippet...
<xsl:element name="Permission">
<xsl:for-each select="UserPermission/Permission">
<xsl:attribute name="@Desc"> <------This is the part that will not
validate
<blah blah blah>

Is what I want to do possible? Does anyone have any sample code?

Regards,

BBL
 
S

Soren Kuula

bprimuslevy said:
I have an XML Document that looks like this...
<UserPermission>
<Permission Desc="DoSomething" Assigned="1" />
<Permission Desc="CanAlsoDo" Assigned="1"/>
</UserPermission>

I would like to transform the document to look like this...

<User Permission>
<Permission DoSomething="1" CanAlsoDo="1"/>
</UserPermission>

This is my xslt snippet...
<xsl:element name="Permission">
<xsl:for-each select="UserPermission/Permission">
<xsl:attribute name="@Desc"> <------This is the part that will not
validate
<blah blah blah>

Is what I want to do possible? Does anyone have any sample code?

Try to put { } around @Desc. By default, attribute names are taken to be
literals; putting it into { } will make it an expression (an attribute
valut template).

Søren
 

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
474,002
Messages
2,570,258
Members
46,857
Latest member
ArleenWill

Latest Threads

Top