xsltexist-dbxinclude

XInclude in XSLT Stylesheets (eXist-db)


Some of my stylesheets are a bit large and some of their parts are repeating. I would like to use XInclude for them—which would allow me to separate them aside the whole stylesheet. I can’t use xsl:import or xsl:include here because I need to inject them into the specific place for generating bookmarks and active links (for XSL-FO).

If I use:

<xi:include href="/db/apps/tested-bunny/resources/xsl-fo/common/bookmark-tree.xml/>

… the .fo file produced really includes the part. However, the part is untranslated, which means it is there as is in the source. The XSL-FO processor thus ignores it and the pdf result is without bookmarks.

As for the separated part—I saved it as a regular XML file with two namespaces declared in the root element:

<fo:bookmark-tree xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format">
    <xsl:if test="$head-level ge '1'">
    ...

If I try to include the same code snippet in a form of XSL stylesheet, it is the same—it is injected there properly but it does not add its functionality to the whole stylesheet, it is there still untranslated.

Is there any specific practice or limitation I am not aware of? How to do that properly?


Solution

  • For me, the working solution was not XInclude but xsl:include and calling the template at the proper time:

    ...
    </fo:declarations>
    <!-- Bookmarks from the external stylesheet -->
    <xsl:call-template name="bookmark-tree"/>
    <fo:page-sequence master-reference="title-page">
    ...
    

    I created the proper stylesheet. The important thing was to set the root element to the current context:

    <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format" version="2.0">
        <xsl:template name="bookmark-tree" match=".">
            <fo:bookmark-tree>
                ...
    

    And of course, it was necessary to include the stylesheet into the one where I call the template:

    <xsl:include href="common/bookmark-tree.xsl"/>
    

    For now, I consider this question as answered.