XSLT Error Reference
Markup in the document following the root element must be well-formed
Error message
org.xml.sax.SAXParseException: The markup in the document following the root element must be well-formed.There is content after the closing tag of the root element — usually two XML documents concatenated, or a fragment list without a wrapper element.
What it means
An XML document has exactly one root element. Once the parser sees the root close, only comments, PIs and whitespace may follow. Any further element or text raises this error.
Common causes
- Concatenated documents. Log pipelines and batch exports often append documents into one file:
<order id="1">…</order>
<order id="2">…</order> <!-- error: second root -->
- A fragment list returned by an API or built by string concatenation, with no enclosing element.
- Leftover text/markup after the root when hand-editing a file.
How to fix it
- Wrap the fragments in a single container element:
<orders>
<order id="1">…</order>
<order id="2">…</order>
</orders>
- If you cannot change the producer, wrap at read time (
concat('<wrap>', $raw, '</wrap>')before parsing withparse-xml()in XSLT 3.0, or wrap in your ingestion code). - In XSLT Playground, paste the wrapped version and your stylesheet can iterate
wrap/ordernormally.