XML转化,xslt问题?
源xml
<database>
<data>
<id> 1 </id>
<code> 1 </code>
<summary> aa </summary>
</data>
<data>
<id> 2 </id>
<code> 2 </code>
<summary> bb </summary>
</data>
<data>
<id> 1 </id>
<code> 3 </code>
<summary> cc </summary>
</data>
<database>
目标XML
<database>
<data>
<id> 1 <id>
<Row>
<code> 1 </code>
<summary> aa </summary>
</Row>
<Row>
<code> 3 </code>
<summary> cc </summary>
</Row>
</data>
<data>
<id> 2 <id>
<Row>
<code> 2 </code>
<summary> bb </summary>
</Row>
</data>
</database>
求高手指教?
[解决办法]
<?xml version= "1.0 " encoding= "UTF-8 "?>
<xsl:stylesheet version= "1.0 " xmlns:xsl= "http://www.w3.org/1999/XSL/Transform ">
<xsl:output indent= "yes " encoding= "UTF-8 " method= "xml "/>
<xsl:template match= "/ ">
<database>
<xsl:for-each select= "//data[not(id=preceding::data/id)] ">
<xsl:variable name= "id " select= "id "/>
<data>
<xsl:copy-of select= "id "/>
<xsl:for-each select= "//data[id=$id] ">
<row>
<xsl:copy-of select= "code "/>
<xsl:copy-of select= "summary "/>
</row>
</xsl:for-each>
</data>
</xsl:for-each>
</database>
</xsl:template>
</xsl:stylesheet>