XSLT - 如何匹配任何非文本节点的子节点?

时间:2021-12-29 19:40:19

I'm new to XSLT and I can't figure out how to get an xsl:if that matches when there are no child tags.

我是XSLT的新手,我无法弄清楚如何获得xsl:如果匹配时没有子标签。

I want this to match:

我希望这匹配:

<context>
    howdy
</context>

And this not:

而这不是:

<context>
    <child>
        howdy
    </child>
</context>

2 个解决方案

#1


the relevant xpath expression should look like:

相关的xpath表达式应如下所示:

//context[not(./*)]

#2


You could also specify count(child::*) = 0 .

您还可以指定count(child :: *)= 0。

#1


the relevant xpath expression should look like:

相关的xpath表达式应如下所示:

//context[not(./*)]

#2


You could also specify count(child::*) = 0 .

您还可以指定count(child :: *)= 0。