I have an xml file which contains the following markup, I know the format of this file is not correct but that's how the file is.
<?xml version="1.0" encoding="UTF-8"?>
<mbean code="org.book.mybooks"
name="mycompany.props.jndi:name=mybookprops">
<attribute name="CombineProps" serialDataType="jbxb">
<jndi:bindings xmlns:jndi="urn:jboss:jndi-binding-service:1.0"
xmlns:xs="http://www.w3.org/2001/XMLSchema-instance"
xs:schemaLocation="urn:jboss:jndi-binding-service:1.0 resource:jndi-binding-service_1_0.xsd">
<jndi:binding name="books/mybooks/cartoon/comics">
<jndi:value type="java.lang.String">
@Value@
</jndi:value>
</jndi:binding>
<jndi:binding name="abc/ebooks/onebook/action">
<jndi:value type="java.lang.String">
@Value@
</jndi:value>
</jndi:binding>
<jndi:binding name="abc/ibooks/twobook/romance">
<jndi:value type="java.lang.String">
@Value@
</jndi:value>
</jndi:binding>
</jndi:bindings>
</attribute>
<mbean code="org.book.mybooks"
name="mycompany.props.jndi:name=mybookprops">
<attribute name="CombineProps" serialDataType="jbxb">
<jndi:bindings xmlns:jndi="urn:jboss:jndi-binding-service:1.0"
xmlns:xs="http://www.w3.org/2001/XMLSchema-instance"
xs:schemaLocation="urn:jboss:jndi-binding-service:1.0 resource:jndi-binding-service_1_0.xsd">
<jndi:binding name="books/mybooks/cartoon/comics">
<jndi:value type="java.lang.String">
@New_Value@
</jndi:value>
</jndi:binding>
<jndi:binding name="abc/ebooks/onebook/action">
<jndi:value type="java.lang.String">
@New_Value@
</jndi:value>
</jndi:binding>
<jndi:binding name="books/new/books/cartoon">
<jndi:value type="java.lang.String">
@Value@
</jndi:value>
</jndi:binding>
</jndi:bindings>
</attribute>
</mbean>
</mbean>
If you observe the file, it contain a child element called <mbean>
with in a parent element <mbean>
, so i want to remove this parent-child and make a one single element <mbean>all parent elements and child elements</mbean>
file.
I have searched few questions in stackoverflow but it looks like they are not exactly related to the problem that i am having right now. Can someone give an idea how to work on this solution using either by xslt 1.0 or 2.0.
This is the final output that i am expecting:
<?xml version="1.0" encoding="UTF-8"?>
<mbean code="org.book.mybooks"
name="mycompany.props.jndi:name=mybookprops">
<attribute name="CombineProps" serialDataType="jbxb">
<jndi:bindings xmlns:jndi="urn:jboss:jndi-binding-service:1.0"
xmlns:xs="http://www.w3.org/2001/XMLSchema-instance"
xs:schemaLocation="urn:jboss:jndi-binding-service:1.0 resource:jndi-binding-service_1_0.xsd">
<jndi:binding name="books/mybooks/cartoon/comics">
<jndi:value type="java.lang.String">
@New_Value@
</jndi:value>
</jndi:binding>
<jndi:binding name="abc/ebooks/onebook/action">
<jndi:value type="java.lang.String">
@New_Value@
</jndi:value>
</jndi:binding>
<jndi:binding name="abc/ibooks/twobook/romance">
<jndi:value type="java.lang.String">
@Value@
</jndi:value>
</jndi:binding>
<jndi:binding name="books/new/books/cartoon">
<jndi:value type="java.lang.String">
@Value@
</jndi:value>
</jndi:binding>
</jndi:bindings>
</attribute>
</mbean>
Simple change the XPATH as I commented in the previous answer. I hope you serve.
You can change paths. First write parent nodes and then the children who does not have the dad.