2013-03-01 131 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>