It is sometime convenient to split up content in several files and include content instead of referring to it using a hyperlink. There are several reasons why this is useful.
Forrest (0.7) already has support for XInclude but unfortunately, the include mechanism is a bit limited. In particular,
Therefore, an extension for includes is needed, at least until Forrest supports it natively. The extension is nothing more than a usability improvement: for its implementation it uses the XInclude mechanism provided by Forrest. The extension consists of:
Beyond this, no additional work is required. Just change the DTD declaration of your document when you want to use the include extension. Existing documents will continue to work.
File | Installation location | Purpose |
---|---|---|
catalog.xcat | project.schema-dir | XML catalog for the extensions |
CatalogManager.properties | project.classes-dir | Configuration to tell Forrest where to find the catalog file. |
includeExtension-v1.dtd | project.schema-dir | Document type declaration for Xdoc with includes. |
absolutize-includes.xsl | project.stylesheets-dir | Stylesheet to absolutize links to links relative to the site root. |
add-cocoon-prefix.xsl | project.stylesheets-dir | Stylesheet to add a cocoon:/ prefix to the included paths so that cocoon can find them. |
dotdots.xsl | project.stylesheets-dir | Stylesheet to transform a path into a sequence of '../' to go back from the given path to the root of the site. This script is actually copied from Forrest itself because I could not figure out how to include it otherwise. |
relativize-links.xsl | project.stylesheets-dir | Stylesheet to process relative links in included file to make them relative to the current file. Also, it relativizes absolute links (those starting with '/') into relative ones. |
sitemap.xmap | project.sitemap-dir | Sitemap file. Comments in the file indicate which parts you need to copy in your own sitemap file. |
To use the extension, it is important to configure your XML editor with the catalog file of Forrest and of the catalog file of our extension. A catalog file tells your XML editor where the DTDs for the used documents can be found so that internet access is not required for validation. The following catalog files must be configured in your XML editor for the extensions:
To create a new document, start from the following template:
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE document PUBLIC "-//WAMBLEE.ORG//ENTITIES Include Extension for Xdoc V1//EN" "includeExtension-v1.dtd"> <document> <header> <title>Your new document</title> </header> <body> <section id="introduction"> <title>Introduction</title> <p>Your text.</p> </section> </body> </document>
The syntax of the include element is as follows:
<include file="site:REF" parse="text|xml" pointer="XPOINTER_EXPR"/>
The file attribute specifies the file to be included. For the value of file attribute, the following types of references can be used:
In any case. The parse attribute describes how to include the source. To include the content of another Xdoc document, you would typically use the value xml for this attribute or omit it. The pointer attribute finally allows you to specify a part of the included XML document using xpointer syntax. The default xpointer expression used is xpointer(//body/*) which means that the content of the body tag of the XML document is included. Beware however that xpointer support does not appear to be that mature right now in Forrest.
To include another Xdoc document you would use
<include file="site:MYFILE"/>
This includes the content from within the body tag of the other document.
To include another file as a code example you would use
<source><include parse="text" file="site:MYFILE"/></source>
For downwards compatibility with Xdoc documents, the include extension allows .html extensions to imply Xdoc files. It replaces the .html extension by .xml to look for the corresponding Xdoc file. This allows standard Xdoc files and the files using the include extension to share the same definitions in the site.xml file.
To include raw XML file without any processing use the .rawxml extension. When Forrest generates the site, it will then replace the extension by .xml. So if your site.xml refers to a file mydir/myfile.rawxml then Forrest will look for a file at mydir/myfile.xml
The include functionality is transitive, that is, it is perfectly ok to include another document which includes another document etc. (who tries out an infinite recursion?).
The use of the pointer attribute is experimental, use at your own risk/frustration.Hyperlinks in included documents also work. You can use the same types of URLs as with the include element, namely site: URLs, relative URLs, and URLs relative to the site root. The last type of URL is an extension with respect to Forrest but can be convenient to include a document whose path is known but where you don't want to define the document in the site.xml.
My Xdoc document contains an include but it looks like this include is not processed at all and I also get no error message. What is wrong?
Make sure that the document type declaration of your xdoc file refers to the correct DTD (see above), otherwise includes will not be processed.
My document gives some obscure error and I don't know what to do.
Try these steps in order:
I am using 'forrest run' but the changes I make do not show up.
It can occur that changes to included documents do not become visible. This is because forrest sometimes caches HTML pages. If you request the same page as the XML source then you will see the changes. An alternative is to view the included file you are editing on its own and not as part of a document in which it is included. Of course, you can also restart forrest.
Cannot get input stream for cocoon:/a/b/c/myfile.ext
If you get this error, you need to configure a rule in your sitemap.xmap for retrieving this type of file. For example:
<map:match pattern="**.ext"> <map:read src="{project:content.xdocs}{1}.txt"/> </map:match>
I do not understand yet why this is occurring but my understanding of cocoon and Forrest is growing.