我需要通过paymentRecordDate排序TranHist节点,然后按帐户余额排序。
我的xml如下:
<data>
<Account>
<accountNumber>12345</accountNumber>
<balance>1400</balance>
</Account>
<Account>
<accountNumber>6789</accountNumber>
<balance>2000</balance>
</Account>
<TranHist>
<accountNumber>12345</accountNumber>
<paymentStatus>CL</paymentStatus>
<paymentRecordDate>20141101</paymentRecordDate>
</TranHist>
<TranHist>
<accountNumber>12345</accountNumber>
<paymentStatus>CL</paymentStatus>
<paymentRecordDate>20141201</paymentRecordDate>
</TranHist>
<TranHist>
<accountNumber>6789</accountNumber>
<paymentStatus>1</paymentStatus>
<paymentRecordDate>20141201</paymentRecordDate>
</TranHist>
<data>
我到目前为止的xslt:
<xsl:variable name="accounts" select="data/Account"/>
<xsl:for-each select="data/TranHist">
<xsl:sort select="number(paymentRecordDate)" order="descending" />
<xsl:sort select="$accounts[accountNumber = ????/accountNumber]/balance" order="descending" />
<xsl:copy-of select="."/>
</xsl:for-each>
如何在for-each上下文的TransHist节点中引用accountNumber?
答案 0 :(得分:2)
如何在TransHist节点中引用accountNumber 每个背景?
执行此操作的最佳方法是使用键。尝试:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:key name="acct" match="Account" use="accountNumber" />
<xsl:template match="/">
<root>
<xsl:for-each select="data/TranHist">
<xsl:sort select="paymentRecordDate" data-type="number" order="descending"/>
<xsl:sort select="key('acct', accountNumber)/balance" data-type="number" order="descending"/>
<xsl:copy-of select="."/>
</xsl:for-each>
</root>
</xsl:template>
</xsl:stylesheet>