In XQuery 3.1 (eXist 4.7) I have an operation that deletes nodes from a stored XML document at /db/apps/myapp/data/list_bibliography.xml that looks like this:
<listBibl xmlns="http://www.tei-c.org/ns/1.0" xml:id="bibliography">
<tei:biblStruct xmlns:tei="http://www.tei-c.org/ns/1.0" type="book" xml:id="Z-BF2WLW8Y">
<tei:monogr>
<tei:title level="m">footitle1</tei:title>
<tei:author>
<tei:name>author name</tei:name>
</tei:author>
<tei:imprint>
<tei:publisher>some city</tei:publisher>
<tei:date>2019</tei:date>
</tei:imprint>
</tei:monogr>
</tei:biblStruct>
<tei:biblStruct xmlns:tei="http://www.tei-c.org/ns/1.0" type="book" xml:id="Z-4KF7YNP3">
<tei:monogr>
<tei:title level="m">footitle2</tei:title>
<tei:author>
<tei:name>author name</tei:name>
</tei:author>
<tei:imprint>
<tei:publisher>some other city</tei:publisher>
<tei:date>2018</tei:date>
</tei:imprint>
</tei:monogr>
</tei:biblStruct>
</listBibl>
The following function:
declare local:delete-bibl()
{
let $bibdoc := doc("/db/apps/myapp/data/list_bibliography.xml")
for $bib in $bibdoc//tei:biblStruct[@xml:id = "Z-BF2WLW8Y"]
return update delete $bib
};
leaves the file with whitespace like this:
<listBibl xmlns="http://www.tei-c.org/ns/1.0" xml:id="bibliography">
<tei:biblStruct xmlns:tei="http://www.tei-c.org/ns/1.0" type="book" xml:id="Z-4KF7YNP3">
<tei:monogr>
<tei:title level="m">footitle2</tei:title>
<tei:author>
<tei:name>author name</tei:name>
</tei:author>
<tei:imprint>
<tei:publisher>some other city</tei:publisher>
<tei:date>2018</tei:date>
</tei:imprint>
</tei:monogr>
</tei:biblStruct>
</listBibl>
Is there some sort of configuration or function that can collapse the white space left by delete?
I tried using instead return update replace $bib with "" but that throws errors as the replacement must be a node.
Many thanks.