我有一个包含以下标记的 xml 文件,我知道该文件的格式不正确,但文件就是这样。
<?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>
如果您观察文件,它包含一个<mbean>
在父元素中调用的子元素<mbean>
,所以我想删除这个父子元素并制作一个单元素<mbean>all parent elements and child elements</mbean>
文件。
我在stackoverflow中搜索了几个问题,但看起来它们与我现在遇到的问题并不完全相关。有人可以通过 xslt 1.0 或 2.0 给出如何处理此解决方案的想法。
这是我期待的最终输出:
<?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>