将具有相同ID的多个节点合并为一个,但附加所有CHILDS [英] merge multiple nodes with SAME ID into one but append all CHILDS
本文介绍了将具有相同ID的多个节点合并为一个,但附加所有CHILDS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果有人可以帮助我解决这部分xmlt,这将是一种好感.
it would be kind if someone can help me with this piece of xmlt.
我要转换此xml片段:
I want to transform this xml piece:
<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>
进入
<root>
<ResultOperationalStatusCategory>
<identifier>1</identifier>
<comment>comment 1</comment>
</ResultOperationalStatusCategory>
<ResultOperationalStatusCategory>
<identifier>2</identifier>
<comment>comment 2</comment>
<comment>comment 3</comment>
</ResultOperationalStatusCategory>
谢谢!
推荐答案
<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>
这篇关于将具有相同ID的多个节点合并为一个,但附加所有CHILDS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文