Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Xml 如何在XSL中获取数组长度?_Xml_Xslt_Apache Fop - Fatal编程技术网

Xml 如何在XSL中获取数组长度?

Xml 如何在XSL中获取数组长度?,xml,xslt,apache-fop,Xml,Xslt,Apache Fop,若数组有元素,我需要显示表,若数组为空,需要显示另一个块?我现在只有一个。我的数组有“items”名称 我想要另一个变体,类似这样,但采用XSL样式: <xsl:if list is empty> <block> There is no elements!!! </block> <xsl:else> <table code> </xsl:if> 没有元素!!! 我怎么能做到?我需要FOP(pdf生成

若数组有元素,我需要显示表,若数组为空,需要显示另一个块?我现在只有一个。我的数组有“items”名称


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

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

没有元素!!!
我怎么能做到?我需要FOP(pdf生成器)的if。

您可以执行以下操作:

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

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