Xslt:根据查找条件排序



我需要按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 ?

的transshist节点中的accountNumber如何引用for - each上下文?
最好的方法是使用。试一试:
<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>

相关内容

  • 没有找到相关文章

最新更新