考虑下面的XML片段:在XSL中可以匹配“none”吗?
<foo>
<bar>1</bar>
<bar>2</bar>
<bar>3</bar>
</foo>
下面的XSL应该工作:
<xsl:template match="/">
<xsl:apply-templates
mode="items"
select="bar" />
</xsl:template>
<xsl:template mode="items" match="bar">
<xsl:value-of select="." />
</xsl:template>
有没有一种方法,我可以使用类似的格式,以这个应用模板,当有没有<bar/>
实体?例如:
<xsl:template match="/">
<xsl:apply-templates
mode="items"
select="bar" />
</xsl:template>
<xsl:template mode="items" match="bar">
<xsl:value-of select="." />
</xsl:template>
<xsl:template mode="items" match="none()">
There are no items.
</xsl:template>
问得好,+1。查看我对exlanation的回答以及仅使用模板并且没有显式条件XSLT指令的完整简短解决方案。 :) –