I have a sequence of strings that I need to parse as XML using XSLT. For example:
<span>Foo</span> & <span>bar</span> have been tagged.
When I try to parse this using fn:parse-xml-fragment (using Saxon-PE 9.6.0.5), two errors are thrown:
If I remove the &
entity from the input text, then it parses correctly. However, if the entity is escaped in the input, why would it cause XML parsing to fail?
If you want to parse XML then with XML an ampersand needs to be escaped as &
and I am sure in a pure XPath context you can do parse-xml-fragment('&')
. If your input is escaped inside XML then of course you need to escape an ampersand as &amp;
:
<data><span>Foo</span> &amp; <span>bar</span> have been tagged.</data>
or
<data><![CDATA[<span>Foo</span> & <span>bar</span> have been tagged.]]></data>