1

I am looking for an XPATH expression that selects child nodes whenever it contains the entire text node of the parent element. e.g.:

<title><italic>Here is my title</italic></title>

(here I want to select italic as it includes the entire content of its parent. but I don't want to select:

<title>Here is my <italic>italic</italic> title</title>

or

<title><bold>Here is my </bold><italic>italic title</italic></title>

(here, italic only contains part of the parents text)

Any ideas? Thanks! Franziska

1 Answers1

1

This XPath,

/*//*[. = ..]

will select all elements beneath the root element whose string value equals that of its parent.

So, for this XML,

<r>
  <title><italic>Here is my title</italic></title>
  <title>Here is my <italic>italic</italic> title</title>
  <title><bold>Here is my </bold><italic>italic title</italic></title>
  <title><italic><bold>Another</bold></italic><italic> case</italic></title>
</r>

the following elements,

<italic>Here is my title</italic>    
<bold>Another</bold>

will be selected.

kjhughes
  • 106,133
  • 27
  • 181
  • 240
  • 1
    Sorry for not being really clear on my requirements, but the XPath you just added works perfectly fine. Thanks a lot! – ffranziiska Mar 21 '17 at 10:35