openSUSE / dbxincluder

Transclusions for DocBook with XInclude 1.1
https://opensuse.github.io/dbxincluder
GNU General Public License v3.0
2 stars 3 forks source link

Support xi:fallback element #16

Closed tomschr closed 8 years ago

tomschr commented 8 years ago

The XInclude specification allows the additional element xi:fallback. For example:

<xi:include href="something_not_available.xml">
  <xi:fallback>
    <para>This will be included</para>
  </xi:fallback>
</xi:include>

The XInclude processor tries to retrieve something_not_available.xml. If that fails, the xi:fallback is considered.

According to the spec (see above link):

The xi:fallback element appears as a child of an xi:include element. It provides a mechanism for recovering from missing resources. When a resource error is encountered, the xi:include element is replaced with the contents of the xi:fallback element. If the xi:fallback element is empty, the xi:include element is removed from the result. If the xi:fallback element is missing, a resource error results in a fatal error.

An interesting side note: the xi:fallback can contain a xi:include which can contain an xi:fallback...

Vogtinator commented 8 years ago

Implementing xi:fallback causes the output to be dependent on external factors. As this is used to create static pages, it is a bad idea to allow that IMO.

tomschr commented 8 years ago

As this is used to create static pages...

That sentence is very misleading. :) The whole XInclude process is to resolve XInclude elements and to create one single XML file. Not more, not less. "Static pages" sounds like you are thinking about HTML which is on a completely different page.

You already download your resource with the urllib library. The only part that is missing is to check for an additional xi:fallback element. If that element is available, copy the contents to your subtree. If it is not available, raise an error (as you already do).

Vogtinator commented 8 years ago

That sentence is very misleading. :) The whole XInclude process is to resolve XInclude elements and to create one single XML file.

dbxincluder's purpose is to be used for DocBook documentation, not a general XInclude 1.1 processor (although it could be made one).

tomschr commented 8 years ago

dbxincluder's purpose is to be used for DocBook documentation, not a general XInclude 1.1 processor (although it could be made one).

Well, actually dbxincluder replaces the internal xinclude() method from lxml. Although this script/project is targeted at DocBook, it should contain the same functionality as the former xinclude() method.

Of course, it doesn't have to be done all at once now. But if dbxincluder should replace/extend other ways, it should be at least feature parity with existing solutions.

Vogtinator commented 8 years ago

Implemented now, see https://github.com/openSUSE/dbxincluder/blob/feature/rewrite/tests/cases/xmlfallback.case.xml

tomschr commented 8 years ago

Great, thanks a lot Fabian! :+1: