DISCUSSION POINT: This needs to be more nuanced since we are not necessarily returning complete TEI or HTML documents.
MH: It might not be returning complete files but the fragment that’s returned must be valid according to the relevant schema when embedded within the code for a minimalist page scaffolding. That is, if you plunked an html result in
<html><head>…</head><body>{result}</body></html>
or
<TEI><teiHeader>...</teiHeader><facsimile>...</facsimile><text><div>{$result}</div></text></TEI>
Within the context of TEI this means that all pointer attributes in the fragment that point internal xml:id identifiers that are also in the fragment. Those that don’t could likely be excluded from the output without any problems.