Based on help from other questions I've asked, I've got this groovy snippet:
NodeList nodes = (NodeList)xpath.evaluate( xpathQuery, records, XPathConstants.NODESET );
return nodes.collect { node -> node.getTextContent() }
Which allows me to perform xpathQuery on records and get the result.
What I want to do now is just return (as a string) the raw xml of the result (rather than the text content) (I realise this will not result in a valid xml document).
Such that:
xml = "<root><apple><color>RED</color></apple>…</root>"
xpathQuery = "/root/apple[1]"
will return:
"<apple><color>RED</color></apple>"
(Without the enclosing <apple> tags would also be fine). Is there a simple way to do this?
Or failing that, is there another way to achieve this?
<xsl:copy-of>.