2011-09-13 10 views
1

xmltのこの部分を手伝ってもらえれば親切です。SAME IDを持つ複数のノードを1つにマージしてすべての子を追加します

<root> 
<ResultOperationalStatusCategory> 
    <identifier>1</identifier> 
    <comment>comment 1</comment> 
</ResultOperationalStatusCategory> 
<ResultOperationalStatusCategory> 
    <identifier>2</identifier> 
    <comment>comment 2</comment> 
    <comment>comment 3</comment> 
</ResultOperationalStatusCategory> 

THANKSに

<root> 
    <rowdata> 
    <ID>1</ID> 
    <pxPages> 
     <rowdata> 
     <comment>comment 1</comment> 
     </rowdata> 
    </pxPages> 
    </rowdata> 
    <rowdata> 
    <ID>2</ID> 
    <pxPages> 
     <rowdata> 
     <comment>comment 2</comment> 
     </rowdata> 
    </pxPages> 
    </rowdata> 
    <rowdata> 
    <ID>2</ID> 
    <pxPages> 
     <rowdata> 
     <comment>comment 3</comment> 
     </rowdata> 
    </pxPages> 
    </rowdata> 
</root> 

私はこのXMLピースを変換したいです!

答えて

0
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> 
    <xsl:output omit-xml-declaration="yes" indent="yes"/> 

    <xsl:key name="k" match="rowdata" use="ID"/> 

    <xsl:template match="/root"> 
    <xsl:copy> 
     <xsl:apply-templates select="rowdata[generate-id(.) = 
          generate-id(key('k', ID))]"/> 
    </xsl:copy> 
    </xsl:template> 

    <xsl:template match="rowdata"> 
    <ResultOperationalStatusCategory> 
     <identifier> 
     <xsl:value-of select="ID"/> 
     </identifier> 
     <xsl:copy-of select="key('k', ID)//comment"/> 
    </ResultOperationalStatusCategory> 
    </xsl:template> 

</xsl:stylesheet> 

出力:

<root> 
    <ResultOperationalStatusCategory> 
    <identifier>1</identifier> 
    <comment>comment 1</comment> 
    </ResultOperationalStatusCategory> 
    <ResultOperationalStatusCategory> 
    <identifier>2</identifier> 
    <comment>comment 2</comment> 
    <comment>comment 3</comment> 
    </ResultOperationalStatusCategory> 
</root> 
+1

@downvoter、コメントをケア? –

関連する問題