I want to remove namespaces from the xml and add an attribute to a tag. How it can be achieved by xslt. Here is the input xml:
<Customers Version="2-0" Type="CustomerInformation" Revision="102" xsi:schemaLocation="http://www.example.com/2011/CustomerInformation-2-0 main-2-0.xsd" xsi:type="CustomerInformationMessage" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.example.com/2011/CustomerInformation">
<header>
<messageId>ABC</messageId>
<creationTimestamp>2015-04-22T11:40:42-05:00</creationTimestamp>
</header>
<CustomerInformation>
<header>
<custType>New</custType>
</header>
<Customer>
<Name>Mat</Name>
<Address>Vegas</Address>
</Customer>
</CustomerInformation>
<CustomerInformation>
<header>
<custType>Update</custType>
</header>
<Customer>
<Name>Gina</Name>
<Address>New York</Address>
</Customer>
</CustomerInformation>
</Customers>
Desired output should be:
<Customers Version="2-0" Type="CustomerInformation" Revision="102">
<header id='ABC'>
<messageId>ABC</messageId>
<creationTimestamp>2015-04-22T11:40:42-05:00</creationTimestamp>
</header>
<CustomerInformation id='ABC'>
<header>
<custType>New</custType>
</header>
<Customer>
<Name>Mat</Name>
<Address>Vegas</Address>
</Customer>
</CustomerInformation>
<CustomerInformation id='ABC'>
<header>
<custType>Update</custType>
</header>
<Customer>
<Name>Gina</Name>
<Address>New York</Address>
</Customer>
</CustomerInformation>
</Customers>
Can someone tell me how to achieve the desired output through xslt version 1.0
Your input xml's namespace is
http://www.example.com/2011/CustomerInformation
, so all the children will inherit that namespace. To get the desired output you want, either remove the namespace from the root of your input file, or give it a new namespace.XSLT: