1
votes

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.

1
I think this leftover whitespace could be considered a bug. Would you consider filing this as a bug report to github.com/eXist-db/exist/issues/new? The sample data and query here would be sufficient to demonstrate it here. Nothing in the docs suggests that users should expect whitespace to be left in place of deleted nodes. - Joe Wicentowski
@joewiz added to github - jbrehr
Many thanks for taking the time to file the issue. - Joe Wicentowski

1 Answers

4
votes

There is no configuration option for collapsing the whitespace left by eXist's XQuery Update delete operations.

To work around the error you received when replacing $bib with an empty string, instead replace it with a text node:

update replace $bib with text { "" }