Copy xml namespace and attributes to other node using xslt

aayush93

New Member
So i'm new to xslt, using it for 2 weeks and now stuck with a problem of copying namespaces and attributes form one node to another.I need to copy namespaces and attributes to another node, remove root node and remove some nodes that are not in new node. The second part removing node can be done in other transformation if it's more easy as i think that should be.Here is input file:\[code\]<?xml version="1.0" encoding="UTF-8"?><xmi:XMI xmlns:namespace1="http://namespace" xmlns:xmi="http://www.omg.org/spec/XMI/20110701" attribute1="some1"><mode><node0>0</node0><node1 attribute2="some2"> <child1 name="a" id="1"/> <child2 name="b" id="2"/></node1></mode><extra1 id="1"/><extra2 id="3"/><xmi:XMI>\[/code\]My needed output:\[code\]<?xml version="1.0" encoding="UTF-8"?><node1 xmlns:namespace1="http://namespace" xmlns:xmi="http://www.omg.org/spec/XMI/20110701" attribute1="some1" attribute2="some2" > <child1 name="a" id="1"/> <child2 name="b" id="2"/></node1><extra1 id="1"/>\[/code\]Probably later will need to keep xmi:XMI node just remove other nodes except node1 and extra1, but think this xsl with modification will help:\[code\]<xsl:stylesheet xmlns:xls="http://www.w3.org/1999/XSL/Transform" xmlns:xmi="http://www.omg.org/spec/XMI/20110701" version="2.0"> <xsl:strip-space elements="*"/> <xsl:output indent="yes" method="xml"/> <xsl:template match="@*|node()"> <xsl:copy> <xsl:apply-templates select="@*|node()"/> </xsl:copy> </xsl:template> <xsl:template match="node"> <xsl:apply-templates select="node()"/> </xsl:template></xsl:stylesheet>\[/code\]I have no ideas right now how to accomplish this. Any help appreciated.
 
Back
Top