the second requirment is that the root tag of the original xml ie the L1 tag should have a namespace added to it
That's not an accurate description of what you show as your output: all the elements that are descendants of the root inherit the root's namespace - therefore you need to add the new namespace to each and every one of them:
XSLT 1.0
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template match="/">
<start>
<a></a>
<!-- ... -->
<Body>
<Envelope>
<xsl:apply-templates select="*" />
</Envelope>
</Body>
</start>
</xsl:template>
<xsl:template match="*">
<xsl:element name="{local-name()}" namespace="www.example.com">
<xsl:apply-templates select="@*|node()"/>
</xsl:element>
</xsl:template>
<xsl:template match="@*">
<xsl:copy/>
</xsl:template>
</xsl:stylesheet>
when the above stylesheet is applied to the corrected input of:
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<L1>
<L2>
<l3>
<item>
<state>1</state>
<currency>LEVEL</currency>
<value1 xmlns:xsi="http://www.w3.org/2001/XMLSchema" xsi:type="xs:int">5</value1>
<value2 xmlns:xsi="http://www.w3.org/2001/XMLSchema" xsi:type="xs:int">ca</value2>
</item>
</l3>
</L2>
</L1>
the result is:
<?xml version="1.0" encoding="UTF-8"?>
<start>
<a/>
<Body>
<Envelope>
<L1 xmlns="www.example.com">
<L2>
<l3>
<item>
<state>1</state>
<currency>LEVEL</currency>
<value1 xmlns:xsi="http://www.w3.org/2001/XMLSchema" xsi:type="xs:int">5</value1>
<value2 xmlns:xsi="http://www.w3.org/2001/XMLSchema" xsi:type="xs:int">ca</value2>
</item>
</l3>
</L2>
</L1>
</Envelope>
</Body>
</start>
Edit
If you want to remove some nodes from the output, create a specific template for them and leave it empty. For example, using the following input:
<L1>
<L2>
<l3>
<item>
<state>1</state>
<currency>
<value1 xmlns:xsi="http://www.w3.org/2001/XMLSchema" xsi:type="xs:int">5</value1>
<value2 xmlns:xsi="http://www.w3.org/2001/XMLSchema" xsi:type="xs:int">ca</value2>
</currency>
</item>
<item2>
<a>1</a>
<b>2</b>
<c>3</c>
</item2>
<item3>
<e>2</e>
<l>3</l>
<m>3</m>
</item3>
<item4>
<n>r</n>
<p>5</p>
</item4>
</l3>
</L2>
</L1>
we will add an empty template for elements <b
, <l>
, <m>
and <p>
to our previous stylesheet:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template match="/">
<start>
<a></a>
<!-- ... -->
<Body>
<Envelope>
<xsl:apply-templates select="*" />
</Envelope>
</Body>
</start>
</xsl:template>
<xsl:template match="*">
<xsl:element name="{local-name()}" namespace="www.example.com">
<xsl:apply-templates select="@*|node()"/>
</xsl:element>
</xsl:template>
<xsl:template match="@*">
<xsl:copy/>
</xsl:template>
<xsl:template match="b|l|m|p"/>
</xsl:stylesheet>
and obtain the following result:
<?xml version="1.0" encoding="UTF-8"?>
<start>
<a/>
<Body>
<Envelope>
<L1 xmlns="www.example.com">
<L2>
<l3>
<item>
<state>1</state>
<currency>
<value1 xmlns:xsi="http://www.w3.org/2001/XMLSchema" xsi:type="xs:int">5</value1>
<value2 xmlns:xsi="http://www.w3.org/2001/XMLSchema" xsi:type="xs:int">ca</value2>
</currency>
</item>
<item2>
<a>1</a>
<c>3</c>
</item2>
<item3>
<e>2</e>
</item3>
<item4>
<n>r</n>
</item4>
</l3>
</L2>
</L1>
</Envelope>
</Body>
</start>