XInclude and Catalog resolution

Tuesday, 1 May 2018 · 2 messages · last reply 2 May 2018
AM
Andreas Mixich1 May 2018 21:43 #
Hello, am I right, that both XML catalogs and XIncludes get only evaluated at document import, not at XQuery execution? If I do
  declare base-uri "http://example.com/restxq-framework/src/";

  let $file := doc("fragments/xhtml5-page.xhtml")
  return $file
and I have an XML Catalog entry like this:
<uri id="RESTXQ-Famework"
name="http://example.com/restxq-framework/src/"
uri="file:///S:/projects/restxqfr/src/"/>
or this:
<rewriteSystem id="RESTXQ-Famework"
systemIdStartString="http://example.com/restxq-framework/src/"
rewritePrefix="file:///S:/projects/restxqfr/src/" />
BaseX tries to load the 'fragments/xhtml5-page.xhtml' from 'example.com/restxq-framework/src/'
-- Goody Bye, Minden jót, Mit freundlichen Grüßen, Andreas Mixich
MS
Michael Seiferle2 May 2018 15:24 #
Hi Andreas, I hope I get your question right, I am no export on catalog resolvers ;-) 1) the doc()-function resolves (relative) paths relative to the base-uri of the static context, that explains why your doc() call fails.
Quoted text · Andreas Mixich · 2 lines
> BaseX tries to load the 'fragments/xhtml5-page.xhtml' from > 'example.com/restxq-framework/src/'
=> basex won’t find that document at example.com <http://example.com/>.
Quoted text · Andreas Mixich · 2 lines
> am I right, that both XML catalogs and XIncludes get only evaluated at > document import, not at XQuery execution?
XIncludes and catalog resolving will happen at document parse time, hence: only if basex successfully found your document it will pass it on to the parser and the parser will try to resolve entities and uris w.r.t. to your catalog file. The doc function will initiate parsing, but it will not look for a catalog by default. To overcome this you may either use the command: set catfile /path/to/catalog.xml, declare option db:catfile „path/to/catalog.xml“ or or you may want to use the fetch:xml function, which imho is the most flexible approach. The following worked for me: 1. Remove the static-base-uri() from your query, as this will affect how doc tries to resolve URLs, but the doc function is not aware of XML catalogs
2. Create a catalog.xml
<catalog xmlns="urn:oasis:names:tc:entity:xmlns:xml:catalog">
    <rewriteSystem systemIdStartString="http://example.com/restxq-framework/src/"
    rewritePrefix="file:///Users/michael/ml/catalog-resolver/"/>
</catalog>
3. XInclude: <xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="http://example.com/restxq-framework/src/fragments/hello.xml"/> 4. Tell the XML parser to make use of your catalog:
fetch:xml(
  "/Users/michael/ml/catalog-resolver/fragments/xhtml5-page.xhtml",
  map {
    "catfile": "/Users/michael/ml/catalog-resolver/catalog.xml“
  }
)
This is what I came up with: https://git.dev.basex.org/snippets/53 <https://git.dev.basex.org/snippets/53> Hope this helps! Best from Konstanz, Michael
-- Michael Seiferle, BaseX GmbH, http://www.basexgmbh.de |-- Firmensitz: Obere Laube 73, 78462 Konstanz |-- Registergericht Freiburg, HRB: 708285, Geschäftsführer: | Dr. Christian Grün, Dr. Alexander Holupirek, Michael Seiferle `-- Tel: +49 7531 916 82 77
Quoted text · Andreas Mixich · 32 lines
> Am 01.05.2018 um 21:43 schrieb Andreas Mixich <mixich.andreas at gmail.com>: > > Hello, > > am I right, that both XML catalogs and XIncludes get only evaluated at > document import, not at XQuery execution? > > If I do > > declare base-uri "http://example.com/restxq-framework/src/"; > > let $file := doc("fragments/xhtml5-page.xhtml") > return $file > > and I have an XML Catalog entry like this: > > <uri id="RESTXQ-Famework" > name="http://example.com/restxq-framework/src/" > uri="file:///S:/projects/restxqfr/src/"/> > > or this: > > <rewriteSystem id="RESTXQ-Famework" > systemIdStartString="http://example.com/restxq-framework/src/" > rewritePrefix="file:///S:/projects/restxqfr/src/" /> > > BaseX tries to load the 'fragments/xhtml5-page.xhtml' from > 'example.com/restxq-framework/src/' > > -- > Goody Bye, Minden jót, Mit freundlichen Grüßen, > Andreas Mixich

⚡Generated with XQuery