我必須將XML轉換爲CSV,但對我而言,轉換是相當困難的。每個週期的XSLT?
這是一個示例XML:
<?xml version="1.0" encoding="windows-1251"?>
<message text="Contract [number] of [sum] [currency] till [deadline]" report="[email protected]">
<customer mobile="X69931232">
<contract number="FL1-22/Ml">
<sum>21,55</sum>
<currency>USD</currency>
<deadline>30.09.2011</deadline>
</contract>
</customer>
<customer mobile="X79484483">
<contract number="FL1-24">
<sum>329,44</sum>
<currency>EUR</currency>
<deadline>30.12.2011</deadline>
</contract>
<contract number="FL1-27">
<sum>232,91</sum>
<currency>EUR</currency>
<deadline>30.12.2011</deadline>
</contract>
</customer>
<customer mobile="X69502060, X79484483">
<contract number="FL1-07">
<sum>42,17</sum>
<currency>USD</currency>
<deadline>30.09.2011</deadline>
</contract>
</customer>
<customer mobile="X69931232, X79484483">
<contract number="FL2-01/M2">
<sum>40,84</sum>
<currency>EUR</currency>
<deadline>30.09.2011</deadline>
</contract>
<contract number="FL1-18">
<sum>198,45</sum>
<currency>EUR</currency>
<deadline>30.11.2011</deadline>
</contract>
</customer>
</message>
和樣品CSV應該像這樣:
X69931232,Contract FL1-22/Ml sum of 21,55 USD till 30.09.2011
X79484483,Contract FL1-24 sum of 329,44 EUR till 30.12.2011; FL1-27 sum of 232,91 EUR till 30.09.2011
X69502060,Contract FL1-07 sum of 42,17 USD till 30.09.2011
X79484483,Contract FL1-07 sum of 42,17 USD till 30.09.2011
X69931232,Contract FL2-01/M2 sum of 40,84 EUR till 30.09.2011; FL1-18 sum of 198,45 EUR till 30.11.2011
X79484483,Contract FL2-01/M2 sum of 40,84 EUR till 30.09.2011; FL1-18 sum of 198,45 EUR till 30.11.2011
我現在的XSLT:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format">
<xsl:template match="/">
Phone,Message
<xsl:for-each select="/message/customer">
<xsl:sort order="ascending" select="contract/@number"/>
<xsl:value-of select="/message/customer/@mobile"/>,
Contract <xsl:value-of select="contract/@number"/> sum of <xsl:value-of select="contract/sum"/>
<xsl:value-of select="contract/currency"/> till <xsl:value-of select="contract/deadline"/>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
如果移動設備屬性包含多個數字,則兩者的文本應相同; 如果每個客戶有多個合同,請發送一個新行。在示例文件中,我展示了每種可能的變體。
謝謝!
您的CSV壞了,逗號在貨幣將導致場分裂。另外,你不相信縮進嗎?請修改您的帖子並正確縮進XML和XSLT。 – 2012-03-16 16:27:04