对于XSLT模板,我需要一个XPath表达式来定位具有特定子元素但没有文本节点的元素。查找具有特定子元素但没有文本节点的元素
<!-- 1: matches -->
<a><b/></a>
<!-- 2: does not match -->
<a>foo bar quux<b/></a>
<!-- 3: does not match -->
<a>whatever <b/> further text</a>
<!-- 4: does not match -->
<a>whatever <b/> further text <b/></a>
<!-- 5: does not match -->
<a><x/><b/></a>
<!-- 6: does not match -->
<a>foo bar quux</a>
我想出了a[*[1 = last() and name() = 'b']]
,但随后情况2或3时,匹配他们不应该。原因当然是,*
选择元素并且不关心文本节点。那我该怎么做呢?
或者,如果你可以接受多个B的,一[B,而不是(* [名称()=” b'])而不是(文字())] – Woody 2012-04-10 08:42:15
完美,非常感谢! – 2012-04-10 08:44:09
@JensBannmann:你可能会对更短,更紧凑的表达感兴趣:) – 2012-04-10 12:24:30