Ticket #68 (closed enhancement: fixed)
Xinclude filter
| Reported by: | bkarwin | Owned by: | hans |
|---|---|---|---|
| Priority: | minor | Milestone: | 2.3.0 |
| Component: | phing-tasks-ext | Version: | 2.2.0 |
| Keywords: | xml filter xinclude | Cc: |
Description
I wanted to use Phing to process some Docbook XML files. One common way of including chapter files in a Docbook book is to use parameter entities. Unfortunately, I found that PHP's XML classes don't support parameter entities (this is a PHP issue, independent of Phing).
So I thought I could use the more modern and flexible Xinclude syntax to include chapter files in my Docbook book, instead of using parameter entities.
Phing doesn't support Xinclude, but PHP's DOM XML class does. So I wrote a filter class to process files using DomDocument::xinclude(). It's very simple. I now have Docbook building from a Phing script.
The implementation is one chained filter class that belongs in the filters subdirectory. Also we need to edit the types/FilterChain.php to recognize the new filter class.
Here's an example of using the xinclude filter, chaining with xsltfilter to render Docbook:
<echo msg="Rendering Docbook manual using Xinclude and XSLT..." />
<copy todir="${manual.dest.dir}">
<filterchain>
<xincludefilter basedir="${manual.src.dir}" />
<xsltfilter style="${manual.src.dir}/html.xsl">
<param name="base.dir" expression="${manual.dest.dir}/" />
</xsltfilter>
</filterchain>
<fileset dir="${manual.src.dir}">
<include name="manual.xml" />
</fileset>
</copy>
The xinclude filter has an argument called basedir. The filter actually changes working directory temporarily to that basedir, so that relative paths referenced in the xinclude tags will work.
Attachments
Change History
Changed 5 years ago by bkarwin
-
attachment
XincludeFilter.php
added

Xinclude filter class.