that script worked thanks. But today my task changed a bit :(
Sorry that first question was not final requirements :(
Now i need to do similar just that:
1) Node can be with namespace and i do not now exact position of node,
can be namespace1:mode/node0/namespace1:parm, but can namespace1:mode/node0/../namespace1:parm
or namespace1:mode/node0/../element or similar but need to find the node by type and name,
where namespace1:type="type1" and name="givenName"
2) It can be that different nodes need to become the root node, from example namespace1:parm or element, but must have tag namespace1:parm everytime.
For first i need to not remove xmi node and no need to merge attributes if there are used nodes .
3) Namespace from can differ every time, don't now how to make this work. Need to remove unused tags.
4) Probably will need another transformation, but when there is just xmi:XMI and namespace1:parm formated tag with no extar tags in xmi:XMI tag, need to merge xmi:XMI with namespace1:parm and retain all attributes and namespaces.
Input:
<?xml version="1.0" encoding="UTF-8"?>
<xmi:XMI xmlns:namespace1="http://namespace" xmlns:xmi="http://www.omg.org/spec/XMI/20110701" attribute1="some1" xmlns:M="mOptions" xmlns:N="nOptions">
<namespace1:mode name="Main">
<node0>0</node0>
<namespace1:parm name="node1" attribute2="some2" namespace1:type="type1">
<child1 name="a" id="1"/>
<child2 name="b" id="2"/>
</namespace1:parm>
<element name="node2" attribute2="some3" namespace1:type="type2">
<child6 name="a6" id="6"/>
<child7 name="b7" id="7"/>
</element>
<node id="55"/>
</namespace1:mode>
<M:extra1 id="1"/>
<M:extra2 id="2"/>
<M:extra6 id="6"/>
<M:extra7 id="7"/>
</xmi:XMI>
First posibility i need similar to last time, need to find everything with namespaces. Tried to modifie the xsl, with no success.
Needed output:
when namespace1:type="type1"
<?xml version="1.0" encoding="UTF-8"?>
<namespace1:parm name="node1" attribute2="some2" namespace1:type="type1">
<child1 name="a" id="1"/>
<child2 name="b" id="2"/>
</namespace1:parm>
<M:extra1 id="1"/>
<M:extra2 id="2"/>
when namespace1:type="type2"
<?xml version="1.0" encoding="UTF-8"?>
<xmi:XMI xmlns:namespace1="http://namespace" xmlns:xmi="http://www.omg.org/spec/XMI/20110701" attribute1="some1" xmlns:M="mOptions" xmlns:N="nOptions">
<namespace1:parm name="node2" attribute2="some3" namespace1:type="type2">
<child6 name="a6" id="6"/>
<child7 name="b7" id="7"/>
</namespace1:parm>
<M:extra6 id="6"/>
<M:extra7 id="7"/>
</xmi:XMI>
and if:
<namespace1:parm name="node2" attribute2="some3" namespace1:type="type2">
<child6 name="a6" id="6"/>
<child7 name="b7" id="7"/>
</namespace1:parm>
</xmi:XMI>
then need
<?xml version="1.0" encoding="UTF-8"?>
<namespace1:parm name="node2" attribute2="some3" namespace1:type="type2"xmlns:namespace1="http://namespace" xmlns:xmi="http://www.omg.org/spec/XMI/20110701" attribute1="some1" xmlns:M="mOptions" xmlns:N="nOptions">
<child6 name="a6" id="6"/>
<child7 name="b7" id="7"/>
</namespace1:parm>
Tried:
<xsl:template match="*">
<xsl:copy>
<xsl:for-each select="@*">
<xsl:attribute name="{name(.)}">
<xsl:value-of select="."/>
</xsl:attribute>
</xsl:for-each>
<xsl:apply-templates select="xmi:XMI|*[@namespace1:type='type1']"/>
</xsl:copy>
</xsl:template>
<xsl:template match="xmi:XMI|*[@namespace1:type='type1']">
<xsl:copy>
<xsl:for-each select="@*">
<xsl:attribute name="{name(.)}">
<xsl:value-of select="."/>
</xsl:attribute>
</xsl:for-each>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
But getting:
<?xml version="1.0" encoding="UTF-8"?>
<xmi:XMI xmlns:namespace1="http://namespace"
xmlns:xmi="http://www.omg.org/spec/XMI/20110701"
xmlns:M="mOptions"
xmlns:N="nOptions"
attribute1="some1">some1<namespace1:mode name="Main">
<namespace1:parm name="node1" attribute2="some2" namespace1:type="type1">node1some2type1<child1 name="a" id="1"/>
<child2 name="b" id="2"/>
</namespace1:parm>
</namespace1:mode>
<M:extra1 id="1"/>
<M:extra2 id="3"/>
<M:extra6 id="6"/>
<M:extra7 id="7"/>
</xmi:XMI>
xmi
but no namespace declaration for that prefix so it is hard to tell what you want to achieve. – Martin Honnen