XSLT Error Reference
The entity name must immediately follow the '&'
Error message
org.xml.sax.SAXParseException: The entity name must immediately follow the '&' in the entity reference.A raw ampersand appears in the XML. In XML, & always starts an entity reference — literal ampersands must be written as &, and only 5 named entities exist.
What it means
In XML, & always begins an entity reference like & or  . A bare & followed by a space, = or anything that is not a valid entity name breaks parsing immediately.
Common causes
- URLs with query strings —
<link>https://x.com/?a=1&b=2</link>. The&bis read as the start of an entity. - Company names and free text —
<name>Johnson & Johnson</name>. - HTML named entities that XML does not define. XML predefines only five:
&<>'". Anything else ( ,é,©…) is an error unless declared in a DTD.
How to fix it
- Escape literal ampersands:
a=1&b=2,Johnson & Johnson. - Replace HTML entities with numeric character references:
→ ,©→©,é→é. - For blocks full of special characters, wrap them in CDATA:
<![CDATA[a=1&b=2 <raw>]]>. - Remember the fix belongs in the producer of the XML: whatever generated the file failed to escape output. Verify the corrected input in XSLT Playground.