1
votes

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

1 Answers

1
votes

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.