How to configure content inclusions

This guide describes how to configure inclusions. Examples of inclusions are the XML inclusions spec and the conref attribute in dita. Because the conref attribute is supported by default in Fonto Editor, this guide will focus on the XML inclusions (XInclude) specification.

In most XML tooling, XInclude is regarded as a pre-processing step. During the parsing of a document, all XInclude elements are resolved and replaced with what they reference. However when editing the XML with the editor, the inclusions should be present in the document so that you can work with them. Therefore, at least in the schema specific for the editor, the XInclude is required to be in the schema for the places where content can be referenced.

This guide uses examples where custom functions are declared in the db namespace "http://www.fontoxml.com/app/docbook". Refer to the guide on namespaces for to learn how to choose a namespace for the editor.

1

Configure the xi:include element as an inclusion

In a configureSxModule, add the following declaration:

JavaScript

configureAsInclusion(sxModule, 'self::xi:include[@href]', 'include',
	{
		functionName: 'resolve-xinclude',
		namespaceUri: 'http://www.fontoxml.com/app/docbook'
	}
);
2

Define the referenced function

In an XQuery module file, add the following import and the following function declaration:

XQuery

module namespace db = "http://www.fontoxml.com/app/docbook";
import module namespace fonto-doc-load = "http://www.fontoxml.com/functions/document-loading";


declare %public function db:resolve-xinclude ($inclusion as element()) as map(*) {
    let $url := $inclusion/@href return
    fonto-doc-load:resolve-content-reference(
        $url,
        function($doc) {$doc/*/*})
};

For more information on XQuery modules refer to the documentation.

A screenshot of external content included in the Editor

The result of an inclusion of an element.