954,517 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Add attribute to an xml using xslt

HI guys,
i have split and xml in two parts, and in the root element element of the second one(which in this case is the output) want to add an attribute...but do not have any idea how to do this...
my XML:

<DataSet>
<Input>
<Order OrderNo="tesco10" DocumentTYpe="0001"/>
</Input>
<Output>
<Order OrderNo="Order1" CompanyCode="ABCD" OrderType="Sales">
<OrderLines>
<OrderLine PrimeLine="1"/>
</OrderLines>
</Order>
</Output>
</DataSet>


my xsl:

<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/DataSet/Output/Order">
<xsl:copy-of select="."/>
<xsl:apply-templates/>
</xsl:template>
</xsl:stylesheet>


the output:

<?xml version="1.0" encoding="UTF-16"?><Order OrderNo="Order1" CompanyCode="ABCD" OrderType="Sales">
<OrderLines>
<OrderLine PrimeLine="1" />
</OrderLines>
</Order>


desired output:

<?xml version="1.0" encoding="UTF-16"?>
<Order OrderNo="Order1" CompanyCode="ABCD" OrderType="Sales" Value="10USD">
<OrderLines>
<OrderLine PrimeLine="1" />
</OrderLines>
</Order>


thanks in advance....

soumya_mjmder
Newbie Poster
13 posts since Apr 2010
Reputation Points: 10
Solved Threads: 0
 

Please try with the below:

<xsl:template match="/DataSet/Output/Order">
<xsl:copy>
<xsl:copy-of select="@*"/>
<xsl:attribute name="test">test</xsl:attribute>
<xsl:copy-of select="*"/>
</xsl:copy>
<xsl:apply-templates/>
</xsl:template>
mrame
Light Poster
37 posts since Feb 2011
Reputation Points: 10
Solved Threads: 4
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: