2
我想處理一些XML進行改革,使該輸入,但是我得到的問題,下面可以更好地說明:XSLT格式化輸出完成90%
INPUT
<?xml version="1.0" encoding="UTF8"?>
<doc:ZINITIALIZE_FILTERS.Response xmlns:doc="urn:sapcom:document:sap:rfc:functions">
<MESSAGE>Success</MESSAGE>
<STATUS>0</STATUS>
<COLLECTION>
<item>
<COLLECTION>A1</COLLECTION>
<SEASON>S09</SEASON>
<TEXT>Spring Market A1</TEXT>
</item>
<item>
<COLLECTION>A1</COLLECTION>
<SEASON>S10</SEASON>
<TEXT>Spring Market A1</TEXT>
</item>
</COLLECTION>
</doc:ZINITIALIZE_FILTERS.Response>
所需的輸出:
<?xml version="1.0" encoding="UTF8"?>
<doc:ZINITIALIZE_FILTERS.Response xmlns:doc="urn:sapcom:document:sap:rfc:functions">
<MESSAGE>Success</MESSAGE>
<STATUS>0</STATUS>
<COLLECTION>
<item>
<COLLECTION>A1</COLLECTION>
<SEASON>S09,S10</SEASON>
<TEXT>Spring Market A1</TEXT>
</item>
</COLLECTION>
</doc:ZINITIALIZE_FILTERS.Response>
XSLT被使用:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
<xsl:output method="xml" indent="yes"/>
<xsl:key name="k" match="item" use="COLLECTION"/>
<xsl:template match="/ZINITIALIZE_FILTERS.Response">
<xsl:copy>
<COLLECTIONS>
<xsl:apply-templates select="COLLECTION/item[generate-id() =
generate-id(key('k', COLLECTION))]"/>
</COLLECTIONS>
</xsl:copy>
</xsl:template>
<xsl:template match="COLLECTION/item">
<xsl:copy>
<xsl:copy-of select="COLLECTION"/>
<SEASON>
<xsl:for-each select="key('k', COLLECTION)">
<xsl:value-of select="SEASON"/>
<xsl:if test="position() != last()">
<xsl:text>,</xsl:text>
</xsl:if>
</xsl:for-each>
</SEASON>
<xsl:copy-of select="TEXT"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
電流不正確的輸出:
<?xml version="1.0" encoding="UTF-8"?>
<ZINITIALIZE_FILTERS.Response xmlns=""><?xml version="1.0"?>
Success0<item xmlns:doc="urn:sap-com:document:sap:rfc:functions"><COLLECTION>A1</COLLECTION><SEASON>S09,S10,S12</SEASON><TEXT>Spring Market A1</TEXT></item>
</ZINITIALIZE_FILTERS.Response>
誰能幫助?
有也刪除這個'的xmlns道:DOC = 「甕:sapcom:文件:SAP:RFC:函數」'?? – MMKD 2012-03-19 13:51:15
@Keevil,從輸出XML中移除? – 2012-03-19 13:54:30
是的輸出。對不起,我不明白 – MMKD 2012-03-19 13:56:50