如何匹配所有只有文本而没有children的节点?
How to mach all nodes that only have text and no children?
这是我的 XML:
<foo>
<a/>
<b>Hello, world!</b>
<c>Hey, <t>Friend!</t></c>
<d><x/></d>
</foo>
我正在尝试创建 XSLT2 模板以仅匹配包含纯文本的节点,例如节点 b
和 t
。我该怎么做?
//*[not(*)]
选择所有没有子元素的元素节点,如果您还想确保元素包含一些非空白文本,请使用 //*[not(*) and normalize-space()]
.
这是我的 XML:
<foo>
<a/>
<b>Hello, world!</b>
<c>Hey, <t>Friend!</t></c>
<d><x/></d>
</foo>
我正在尝试创建 XSLT2 模板以仅匹配包含纯文本的节点,例如节点 b
和 t
。我该怎么做?
//*[not(*)]
选择所有没有子元素的元素节点,如果您还想确保元素包含一些非空白文本,请使用 //*[not(*) and normalize-space()]
.