因此,您需要检查是否有多个图像。当有零或一个时,什么都不显示,当有多个时,显示(最多)前四个?那么怎么样
<xsl:if test="count($extraimages/productimages/productimage) > 1">
<xsl:for-each select="($extraimages/productimages/productimage)[position() <= 4]">
<li>something</li>
</xsl:for-each>
</xsl:if>
括号有所作为,如果有一个以上的productimages
元素$extraimages
- 用括号你会得到不超过四个图像,没有他们,你会得到所有productimage
元素是在其各自的productimages
子元素的前四个productimage
子元素内,其可能总共超过四个。
您还可以在你的榜样的extension
检查中的问题,纳入你会做这样的事情
<xsl:if test="count($extraimages/productimages/productimage[extension != '.pdf']) > 1">
<xsl:for-each select="($extraimages/productimages/productimage[extension != '.pdf'])[position() <= 4]">
<li>something</li>
</xsl:for-each>
</xsl:if>
再次括号可能会或可能不会取决于$extraimages
结构是必要的。
如果你想显示的图像2-5而不是1-4,那么你不需要if
,它只是变得
<xsl:for-each select="
($extraimages/productimages/productimage[extension != '.pdf'])
[position() > 1][position() <= 5]">
<li>something</li>
</xsl:for-each>
因为select
将选择什么都没有,如果有比少两个非pdf图像。