大虾:xsl xml转换问题(在线等。。对了立马给分)
源xml:
<root>
<common>
<building_id>XXXXXX</building_id >
<gateway_id>XXX</gateway_id >
<type>以下5种操作类型之一</type>
</common>
<data operation="query/reply/report/continuous/continuous_ack">
<sequence>XXXXXXXX</sequence>
<parser>yes/no</parser>
<time> YYYYMMDDHHMMSS </time>
<total>XXX</total>
<current>XXX</current>
<meter id="1">
<function id="1" coding="XXX" error="XXX">数据1</function>
<function id="2" coding="XXX" error="XXX">数据2</function>
</meter>
<meter id="2">
<function id="1" coding="XXX" error="XXX">数据1</function>
<function id="2" coding="XXX" error="XXX">数据2</function>
</meter>
</data>
</root>
目标xml:
<root>
<data>
<time>YYYYMMDDMMSS</time>
<meter id="1">
<function id="1" coding="XXX" error="XXX">数据1</function>
<function id="2" coding="XXX" error="XXX">数据2</function>
</meter>
<meter id="2">
<function id="1" coding="XXX" error="XXX">数据1</function>
<function id="2" coding="XXX" error="XXX">数据2</function>
</meter>
</data>
</root>
[解决办法]
这是xsl代码: 试试在你的环境里有没有问题.
<?xml version="1.0" encoding="utf-8"?><xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl"> <xsl:output method="xml" indent="yes"/> <xsl:template match="root"> <xsl:copy> <xsl:for-each select="data"> <xsl:copy> <xsl:for-each select="time"> <xsl:copy> <xsl:apply-templates select="node()"/> </xsl:copy> </xsl:for-each> <xsl:for-each select="meter"> <xsl:copy> <xsl:for-each select="@* | node()"> <xsl:copy> <xsl:for-each select="@* | node()"> <xsl:copy> <xsl:apply-templates select="@* | node()"/> </xsl:copy> </xsl:for-each> </xsl:copy> </xsl:for-each> </xsl:copy> </xsl:for-each> </xsl:copy> </xsl:for-each> </xsl:copy> </xsl:template></xsl:stylesheet>