2013-03-01 134 views
0

我需要显示表,如果数组有元素,还有一些其他块,如果数组是空的?我现在只有 - 每一个。我的数组有“项目”的名称。如何在XSL中获取数组长度?

<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> 

我可怎么办呢?我需要如果为FOP(PDF生成器)。

回答

2

你可以这样做:

<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>