You can use XML objects to create an XML file that defines an nbsp object and includes an (broken) XML fragment.
For example, suppose your fragment is saved as a file with the name: "invalid.xml"
<div><span> some text</span></div>
Create the XML file as follows:
<!DOCTYPE wrapper [ <!ENTITY nbsp " "> <!ENTITY invalid-xml-document SYSTEM "./invalid.xml"> ]><wrapper> &invalid-xml-document;</wrapper>
When it is parsed, it will define the nbsp object, include the contents from "invalid.xml", and resolve the nbsp object properly. The result is the following:
<wrapper> <div> <span> some text</span> </div> </wrapper>
Then simply configure XSLT to place the new document element (in this example, the <wrapper> element).
source share