1

私は次の方法を探しています:

  1. 名前または値が類似しているノードをマージします。
  2. マージ後、ノードの重複した属性を削除します。
  3. 2 つの属性が異なる値を持つ場合、最初の属性の値は、マージされた 2 番目の属性の値に置き換える必要があります。

サンプルコードは次のとおりです。

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<books>
    <mbean code="abc.def.ghi" name="com.booking.props:name=abcdefgh"> 
        <attribute name="BName">abc123</attribute> 
        <depends optional-attribute-name="Bookname">mypersonnelbook</depends> 
        <attribute name="Type1">book.type1.name</attribute> 
        <attribute name="Properties"> 
            bookname=book1
            price=100 
        </attribute> 
    </mbean>
    <mbean code="abc.def.ghi" name="com.booking.props:name=abcdefgh"> 
        <attribute name="BName">abc123</attribute> 
        <depends optional-attribute-name="Bookname">mypersonnelbook</depends> 
        <attribute name="Type2">book.type2.name</attribute>         
        <attribute name="Properties"> 
            bookname=book1
            price=100 
        </attribute> 
    </mbean>
    <us-country-factory>
        <jndi-name>books/props/Classic</jndi-name> 
        <file-name>book1</file-name> 
        <state-location>central.wharehouse</state-location> 
        <store-property name="store" type="java.lang.String">abc</store-property> 
        <store-property name="storetype" type="java.lang.String">1223</store-property> 
        <store-property name="storelocation" type="java.lang.String">defsdgfd</store-property> 
        <store-property name="storecategory" type="java.lang.String">hjtbngb</store-property> 
    </us-country-factory>
    <us-country-factory>
        <jndi-name>books/props/Classic</jndi-name> 
        <file-name>book1</file-name> 
        <state-location>central.wharehouse</state-location> 
        <store-property name="store" type="java.lang.String">defghij</store-property> 
        <store-property name="storetype" type="java.lang.String">1223</store-property> 
        <store-property name="storelocation" type="java.lang.String">32das</store-property> 
        <store-property name="storecategory" type="java.lang.String">hjtbngb</store-property> 
        <store-property name="storeratings" type="java.lang.String">5</store-property> 

私が探している出力は次のとおりです。

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<books>
    <mbean code="abc.def.ghi" name="com.booking.props:name=abcdefgh"> 
        <attribute name="BName">abc123</attribute> 
        <depends optional-attribute-name="Bookname">mypersonnelbook</depends> 
        <attribute name="Type1">book.type1.name</attribute> 
        <attribute name="Type2">book.type2.name</attribute> 
        <attribute name="Properties"> 
            bookname=book1
            price=100 
        </attribute> 
    </mbean>
    <us-country-factory>
        <jndi-name>books/props/Classic</jndi-name> 
        <file-name>book1</file-name> 
        <state-location>central.wharehouse</state-location> 
        <store-property name="store" type="java.lang.String">defghij</store-property>  
        <store-property name="storetype" type="java.lang.String">1223</store-property> 
        <store-property name="storelocation" type="java.lang.String">32das</store-property> 
        <store-property name="storecategory" type="java.lang.String">hjtbngb</store-property> 
        <store-property name="storeratings" type="java.lang.String">5</store-property> 
    </us-country-factory>   
</books>

        </us-country-factory>   
    </books>

これは私が試したxslファイルです:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output omit-xml-declaration="yes" indent="yes"/>
    <xsl:strip-space elements="*"/>
    <xsl:key name="mbeanName" match="//mbean/@name" use="."/>
    <xsl:key name="mbeanCount" match="//mbean[generate-id(@name) = generate-id(key('mbeanName', @name)[1])]" use="count(.)"/>
    <xsl:key name="us-country-factoryName" match="//us-country-factory[jndi-name/text()]" use="."/>
    <xsl:key name="us-country-factoryCount" match="/us-country-factory[generate-id(jndi-name/text()) = generate-id(key('us-country-factoryName', jndi-name/text())[1])]" use="count(.)"/>

 <xsl:template match="node()|@*">
        <xsl:copy>
            <xsl:apply-templates select="node()|@*"/>
        </xsl:copy>
    </xsl:template>
    <xsl:template match="mbean[count(. | key('mbeanCount', /mbean/@name))]" />
    <xsl:template match="mbean[count(. | key('us-country-factoryCount', us-country-factory[jndi-name/text()]))]" />
</xsl:stylesheet>
4

1 に答える 1