Xml 如何在XSL中获取数组长度?
若数组有元素,我需要显示表,若数组为空,需要显示另一个块?我现在只有一个。我的数组有“items”名称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生成
我想要另一个变体,类似这样,但采用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>