freemarker / fmpp

Command line and Ant tool for processing files with FreeMarker
http://fmpp.sourceforge.net/
Other
82 stars 24 forks source link

XInclude and XML rendering #26

Open MarinBernard opened 5 years ago

MarinBernard commented 5 years ago

Hi,

I'm new to FMPP and I'm trying to have it render a single XML document to a very basic one-liner text file. Templating does work as expected, except regarding the XInclude feature: I can't make FMPP apply the transclusion. In the called template, browsing the DOM with pp.doc returns an xi:include element instead of the target one.

XInclude does work when used with static XML data sources (defined in the main config file), but not with dynamic XML rendering. I use the latest version. What did I forget ?

Config file

recommendedDefaults: 0.9.16
sourceRoot: /home/marin/fmpp/in
outputRoot: /home/marin/fmpp/out
dataRoot:   /home/marin/fmpp/data

modes : [
    ignore(/templates/)
]

data: {
    # Works fine: <xi:include> elements are processed.
    works: xml(music/works/bach/bwv622.xml, {'xincludeAware': true})
}

xmlRenderings: [
    {
        # Does NOT work: <xi:include> elements are returned as-is.
        ifDocumentElementIs: release
        template: templates/release.tags
        xincludeAware: true
        xmlns: {D: http://www.w3.org/1999/xhtml, xi: http://www.w3.org/2001/XInclude}
    }
]

Source XML file

<release xmlns="http://www.w3.org/1999/xhtml"
         xmlns:xi="http://www.w3.org/2001/XInclude">
    <title>My release</title>
    <performances>
        <performance>
            <work>
                <xi:include href="/home/marin/fmpp/data/music/works/bach/bwv622.xml" parse="xml"/>
            </work>
        </performance>
    </performances>
</release>

Template

<#ftl ns_prefixes={"D":"http://www.w3.org/1999/xhtml"}>
<@pp.renameOutputFile extension="txt" />
<#assign release = pp.doc.release>
<#list release.performances.performance.work.* as c>
- ${c?node_name}
</#list>

Output

- include

Instead of the the root element from "/home/marin/fmpp/data/music/works/bach/bwv622.xml".

ddekany commented 5 years ago

Indeed, xincludeAware had no effect inside xmlRenderings. I have fixed this in commit https://github.com/freemarker/fmpp/commit/adfe51f7916dbebb5b2bc15ee478d2f407580743.

MarinBernard commented 5 years ago

Hi,

Many thanks for adding this feature. For your information I noticed that xincludeAware was also ineffective when passed as a parameter of pp.loadData. XML data are loaded but XInclude elements are left unprocessed.

Many thanks. I'll try to build 9.1.17 and see what happens.

ddekany commented 5 years ago

Are you sure about pp.loadData? Looking at the source code, I don't think it ignores the { 'xincludeAware': true } argument you pass to it.