I'm attempting to clean-up a batch of XML I've been provided. There are three situations I need to account for:
- some elements have plain text within them, eg.
<item>some text</item>
, which need to be wrapped in another tag, eg.<item><p>some text</p></item>
- some elements have escaped XML within them, eg.
<item><p>some text</p></item>
, which needs to be output without escaping:<item><p>some text</p></item>
- some elements have escaped XML which needs to be wrapped, eg.
<item>some <em>text</em></item>
needs to become<item><p>some <em>text</em></p></item>
<item>
is used as a container in both instances.
I can satisfy condition one relatively easily, and I can satisfy condition 2 with disable-output-escaping
, but I can't satisfy condition 3 with this approach.
I think I can satisfy 2 (& possibly 3) if I can test whether the text within <item>
is escaped, but a test using contains(., '&lt;')
doesn't match. So...
How can I test whether text within a node is escaped XML?