【问题标题】:How to get array length in XSL?如何在 XSL 中获取数组长度?
【发布时间】:2013-03-01 12:32:49
【问题描述】:

如果数组有元素,我需要显示表格,如果数组为空,我需要显示另一个块?我现在只有 for-each。我的数组有“项目”名称。

<some table header code...>
<xsl:for-each select="items/item">
    <some row code...>
</xsl:for-each>

我想要另一个变体,类似这样,但采用 XSL 样式:

<xsl:if list is empty>
    <block> There is no elements!!! </block>
<xsl:else>
    <table code>
</xsl:if>

我该怎么做?我需要 if for FOP(pdf 生成器)。

【问题讨论】:

    标签: xml xslt apache-fop


    【解决方案1】:

    你可以这样做:

    <xsl:choose>
       <xsl:when test="items/item">
           <xsl:for-each select="items/item">
                <some row code...>
           </xsl:for-each>
       </xsl:when>
       <xsl:otherwise>
           <block>  ... </block>
       </xsl:otherwise>
    </xsl:choose>
    

    但这会是更好的方法:

    <xsl:apply-templates select="items[not(item)] | items/item" />
    
    ...
    
    <xsl:template match="items">
       <block> ... </block>
    </xsl:template>
    
    <xsl:template match="item">
       <!-- Row code -->
    </xsl:template>
    

    【讨论】:

      猜你喜欢
      • 2017-06-19
      • 2022-09-23
      • 2012-03-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-02-14
      • 1970-01-01
      相关资源
      最近更新 更多