如果我有这个XML输入,我想转换:
<Money>
<Balance>
<Type>
<BalCode>FW</BalCode>
</Type>
<Amount Ccy="PHP">4.00</Amount>
<CreditDebit>CRD</CreditDebit>
<Date>2013-08-19</Date>
</Balance>
<Balance>
<Type>
<BalCode>OP</BalCode>
</Type>
<Amount Ccy="PHP">5.00</Amount>
<CreditDebit>CRD</CreditDebit>
<Date>2013-08-19</Date>
</Balance>
<Balance>
<Type>
<BalCode>CL</BalCode>
</Type>
<Amount Ccy="PHP">6.00</Amount>
<CreditDebit>DBT</CreditDebit>
<Date>2013-08-19</Date>
</Balance>
</Money>
我希望有这样的东西作为我的输出:
<Balances>
<BalanceDate>2013-08-19</BalanceDate> <!--From Closing Date-->
<Opening Ccy="PHP">5.00</Opening>
<Closing Ccy="PHP">6.00</Closing>
</Balances>
如何使用XSLT实现此目的。
谢谢和问候
答案 0 :(得分:1)
尝试以下样式表:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:strip-space elements="*"/>
<xsl:output indent="yes" omit-xml-declaration="yes"/>
<xsl:template match="/">
<Balances>
<BalanceDate><xsl:value-of select="Money/Balance[Type/BalCode='CL']/Date"/></BalanceDate>
<xsl:copy-of select="Money/Balance[Type/BalCode='OP']/Amount"/>
<xsl:copy-of select="Money/Balance[Type/BalCode='CL']/Amount"/>
</Balances>
</xsl:template>
</xsl:stylesheet>