我有 xslt 将 xml 文件转换为逗号分隔的文件,但是在每条记录之后它都会创建额外的行。
我试过放,但没有用。任何可以提供帮助的帮助或链接将不胜感激。
资源:
<XML>
<Record><GroupId>2001</GroupId><Date>05-May-2012</Date><Time>10:20:38</Time><TxnId>267-2001-1-29555-2</TxnId><AgencyID>OrdinaryAccountWithdraw</AgencyID><AccTechAgencyType>Out Payment</AccTechAgencyType><AccTechAgencyAmount>30000</AccTechAgencyAmount><CustomerRef>703589491001</CustomerRef></Record>
<Record><GroupId>2001</GroupId><Date>05-May-2012</Date><Time>13:21:50</Time><TxnId>267-2001-1-29694-2</TxnId><AgencyID>SpecialAccountWithdraw</AgencyID><AccTechAgencyType>Out Payment</AccTechAgencyType><AccTechAgencyAmount>20000</AccTechAgencyAmount><CustomerRef>703677841501</CustomerRef></Record>
<Record><GroupId>2001</GroupId><Date>07-May-2012</Date><Time>10:10:08</Time><TxnId>267-2001-1-29780-2</TxnId><AgencyID>InPay_FuneralPlan</AgencyID><AccTechAgencyType>In Payment</AccTechAgencyType><AccTechAgencyAmount>5000</AccTechAgencyAmount><CustomerRef>MP007235</CustomerRef></Record>
<Record><GroupId>2001</GroupId><Date>07-May-2012</Date><Time>10:15:36</Time><TxnId>267-2001-1-29786-2</TxnId><AgencyID>SpecialAccountWithdraw</AgencyID><AccTechAgencyType>Out Payment</AccTechAgencyType><AccTechAgencyAmount>30000</AccTechAgencyAmount><CustomerRef>703690771501</CustomerRef></Record>
<Record><GroupId>2001</GroupId><Date>07-May-2012</Date><Time>10:27:42</Time><TxnId>267-2001-1-29798-3</TxnId><AgencyID>SpecialAccountDeposit</AgencyID><AccTechAgencyType>In Payment</AccTechAgencyType><AccTechAgencyAmount>50000</AccTechAgencyAmount><CustomerRef>703437751501</CustomerRef></Record>
</XML>
xslt:
<?xml version='1.0' ?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0" xmlns:msxsl="urn:schemas-microsoft-com:xslt" xmlns:user="http://mycompany.com/mynamespace"> <xsl:output method="text"/>
<xsl:strip-space elements="*"/>
<xsl:template name="format-date">
<xsl:param name="AGDateValue">01-Jan-2000</xsl:param>
<xsl:value-of select="substring($AGDateValue, 8, 4)"/>
<xsl:choose>
<xsl:when test="substring($AGDateValue, 4, 3) = 'Jan'">01</xsl:when>
<xsl:when test="substring($AGDateValue, 4, 3) = 'Feb'">02</xsl:when>
<xsl:when test="substring($AGDateValue, 4, 3) = 'Mar'">03</xsl:when>
<xsl:when test="substring($AGDateValue, 4, 3) = 'Apr'">04</xsl:when>
<xsl:when test="substring($AGDateValue, 4, 3) = 'May'">05</xsl:when>
<xsl:when test="substring($AGDateValue, 4, 3) = 'Jun'">06</xsl:when>
<xsl:when test="substring($AGDateValue, 4, 3) = 'Jul'">07</xsl:when>
<xsl:when test="substring($AGDateValue, 4, 3) = 'Aug'">08</xsl:when>
<xsl:when test="substring($AGDateValue, 4, 3) = 'Sep'">09</xsl:when>
<xsl:when test="substring($AGDateValue, 4, 3) = 'Oct'">10</xsl:when>
<xsl:when test="substring($AGDateValue, 4, 3) = 'Nov'">11</xsl:when>
<xsl:when test="substring($AGDateValue, 4, 3) = 'Dec'">12</xsl:when>
<xsl:otherwise>00</xsl:otherwise>
</xsl:choose>
<xsl:value-of select="substring($AGDateValue, 1, 2)"/>
</xsl:template>
<xsl:template name="format-time">
<xsl:param name="AGTimeValue">12:12:12</xsl:param>
<xsl:text>T</xsl:text>
<xsl:value-of select="substring($AGTimeValue, 1, 2)"/>
<xsl:value-of select="substring($AGTimeValue, 4, 2)"/>
</xsl:template>
<xsl:template match="/">
<xsl:for-each select="/XML/Record">
<xsl:value-of select="GroupId" />
<xsl:text>|</xsl:text>
<xsl:call-template name="format-date"><xsl:with-param name="AGDateValue" select="Date" /></xsl:call-template>
<xsl:call-template name="format-time"><xsl:with-param name="AGTimeValue" select="Time" /></xsl:call-template>
<xsl:text>|</xsl:text>
<xsl:value-of select="AgencyID" />
<xsl:text>|</xsl:text>
<xsl:value-of select="AccTechAgencyType" />
<xsl:text>|</xsl:text>
<xsl:value-of select="CustomerRef" />
<xsl:text>|</xsl:text>
<xsl:text>|</xsl:text>
<xsl:value-of select="TxnId" />
<xsl:text>|</xsl:text>
<xsl:value-of select="format-number(AccTechAgencyAmount*0.01,'0.00')" />
<xsl:text>
</xsl:text>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
输出:
2001|20120505T1020|OrdinaryAccountWithdraw|Out Payment|703589||267-2001-1-29555-2|300.00
2001|20120505T1321|SpecialAccountWithdraw|Out Payment|703677||267-2001-1-29694-2|200.00
2001|20120507T1010|InPay_FuneralPlan|In Payment|MP00723||267-2001-1-29780-2|50.00
2001|20120507T1015|SpecialAccountWithdraw|Out Payment|703690||267-2001-1-29786-2|300.00
2001|20120507T1027|SpecialAccountDeposit|In Payment|7034377||267-2001-1-29798-3|500.00