eXist-db / exist

eXist Native XML Database and Application Platform
https://exist-db.org
GNU Lesser General Public License v2.1
429 stars 179 forks source link

[BUG] Unable to disable xinclude expansion in eXist 5.0+ serialization? #3446

Open jeanpaulrehr opened 4 years ago

jeanpaulrehr commented 4 years ago

According to the release notes for 5.0+ the function util:serialize has been removed in favour of the standardized fn:serialize(). With the removal of this function, the capacity to dynamically pass the serialization option xinclude=false has been lost.

In theory one should then be able to configure Saxon to take the option (Adam Retter says should in this bug report).

The following is the configuration I tested between eXist and Saxon.

eXist's conf.xml:

<transformer class="net.sf.saxon.TransformerFactoryImpl" caching="no">
      <attribute name="http://saxon.sf.net/feature/version-warning" value="false" type="boolean"/>
      <attribute name="http://saxon.sf.net/feature/configuration-file" value="/Applications/eXist-db-5.2/etc/saxon-config.xml" type="string"/>
   </transformer>

Saxon's saxon-config.xml :

<configuration xmlns="http://saxon.sf.net/ns/configuration" edition="HE">
    <global xInclude="false"/>
</configuration>

This configuration has no effect, although Saxon is definitely receiving the config file.

I posted the question over at Stack Overflow and Michael Kay responded:

Saxon won't ask the parser to expand XIncludes by default, so there should be no need to switch it off. The expansion must be happening somewhere outside Saxon's control, and to pin that down, we need to know more about your overall workflow. Remember that Saxon doesn't expand XIncludes itself, it merely passes the request on to the XML parser. But that's only relevant if the parsing is being controlled through Saxon, which is not necessarily the case.

The interesting point is that Kay states the expansion must be happening outside Saxon as it is switched off by default in Saxon.

Where is the switch for expansion?

-- test --

With the above eXist and Saxon configuration, put the attached two documents in the same directory, then execute this query:

xquery version "3.1";

let $file := /db/apps/{app}/test_doc.xml
return serialize($file)

--- Context --- Version eXist 5.2 (installed with tar) MacOS 10.14.6

joewiz commented 4 years ago

From our discussion in Slack:

@joewiz:

I just searched and found that I wrote something about this up in the eXist 4.7 era: https://github.com/eXist-db/exist/issues/2394 (it was actually related to a StackOverflow question @jeanpaulrehr asked). The util:serialize function was removed in Adam’s omnibus https://github.com/eXist-db/exist/pull/2603 PR.

@AdamRetter Were you aware that there are some eXist-specific serialization parameters that fn:serialize is not recognizing? Do you think we could hook fn:serialize back up to support those legacy parameters, or should util:serialize be restored solely to support these legacy serialization parameters?

@adamretter:

So I guess for fn:serialize we would have tried to follow the spec. It should probably be extended with the eXist options

From this I take it that the best way to resolve issue would be to extend fn:serialize with expand-xincludes and possibly the other eXist options that were also cut off with the removal of util:serialize (comparing the serialization options listed in https://exist-db.org/exist/apps/doc/xquery#legacy-serialization to those in https://www.w3.org/TR/xslt-xquery-serialization-31/):