考慮下面的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指令的完整簡短解決方案。 :) –