對於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