簡體   English   中英

如何為xsl for-each語句添加條件

[英]How to add conditions to xsl for-each statements

我想過濾掉低於$ 1,000,000的任何金額。 這是代碼:

<xsl:for-each select="row">
   <tr>
      <xsl:for-each select="cell">
         <xsl:if test="position()=5">
            <td width="140" style="vertical-align: top; padding: 3px;" valign="top">
                 <xsl:choose>
                  <xsl:when test="@href">
                     <a href="">
                        <xsl:attribute name="href">
                           <xsl:value-of select="@href" />
                        </xsl:attribute>
                        <xsl:value-of select="." />
                     </a>
                  </xsl:when>
                  <xsl:otherwise>
                     <xsl:value-of select="." />
                  </xsl:otherwise>
               </xsl:choose>
            </td>
         </xsl:if>
         <xsl:if test="position()=8">
            <td class="categorydetail-last-column" style="text-align: right; vertical-align: top; padding: 3px;" align="right" valign="top">
               <xsl:value-of select="." /><!-- THIS OUTPUTS NUMBERS. WANT TO FILTER NUMBERS BELOW 1000000 -->
            </td>
         </xsl:if>
      </xsl:for-each>
   </tr>
</xsl:for-each>

它輸出美元金額,但如果大於一百萬則需要輸出。 我嘗試創建變量並將整個代碼包裝在IF語句中,但是沒有用。 我究竟做錯了什么? 我是否必須向ROW添加條件?

據我了解,您只想處理第8號單元格包含的值小於一百萬的行。

因此,使用match條件僅指定此過濾條件的模板:

<xsl:template match="row[cell[8] &lt; 1000000]">
  ...
</xsl:template>

如果您的XSLT腳本還包含一個身份模板 ,則必須以某種方式“阻止”其他行進行處理。 您可以對所有行使用“更通用”的模板來執行此操作

<xsl:template match="row"/>

實際上,它將應用於所有“其他”行(以前的模板不適用)。

另一個解決方案 (更接近於您發布的腳本):

將“外部”循環更改為:

<xsl:for-each select="row[cell[8] &lt; 1000000]">

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM