Q: XPath: How do I include elements in the result I have an XML that looks like this:
<group type="body">
  <element type="body">Some <strong>text</strong></element>
  <element type="body">Some text <a href="http://www.foo.bar">link</a> more text</element>
</group>

And I want a result that looks like this:
<p>Some <strong>text</strong></p>
<p>Some text <a href="http://www.foo.bar">link</a> more text</p>

Currently I have a XPath that looks like this:
concat('<p>',string-join(/*:group[@type = 'body']/*:element[@type = 'body']/normalize-space(), '</p>&#xa;<p>'), '</p>')

My problem is that I can't find a solution where I can include the <a> and <strong> in the result. Anyone with a good idea how to solve this? 

A: XPath can only be used to locate nodes in the source document, it cannot be used to construct new nodes, or to construct and manipulate an XML serialization of the nodes in the source. For that job you need XSLT or XQuery.
(Actually, with XPath 3.1 you could do this the way you are trying to do it, by taking advantage of the new fn:parse-xml and fn:serialize functions. But XQuery/XSLT would still be a much better solution, especially as there are few processors that support XPath 3.1 without also supporting XSLT or XQuery or both).
