是否有可能在XSL中匹配"none"?

Phi*_*ham 3 xslt

给出以下XML片段:

<foo>
  <bar>1</bar>
  <bar>2</bar>
  <bar>3</bar>
</foo>
Run Code Online (Sandbox Code Playgroud)

以下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>
Run Code Online (Sandbox Code Playgroud)

有没有一种方法可以使用类似的格式在没有 <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>
Run Code Online (Sandbox Code Playgroud)

小智 5

是.

但逻辑应该是:

<xsl:template match="foo">
   <xsl:apply-templates select="bar"/>
</xsl:template>

<xsl:template match="foo[not(bar)]">
   There are no items. 
</xsl:template> 
Run Code Online (Sandbox Code Playgroud)

注意:foo是有或没有bar孩子的元素.