Re: [FreeMarker-user] freemarker xml/xslt functions
Generates text that depends on changing data (like dynamic HTML).
Brought to you by:
revusky
|
From: Russell S. <rus...@ho...> - 2005-12-21 21:44:12
|
>Another way is just to expose a POJO that does it and returns an
>instance of org.w3c.dom.Element or whatever (actually we support JDOM
>and DOM4J as well) and that will get wrapped transparently into a
>NodeModel object that can be used from the template side.
So you suggest above something like this (much left of for sake of list)
public class Helper {
public Document load(String xml) {
File inFile= new File(xml);
Document docNode = builder.parse(inFile);
TemplateModel document = new NodeListModel(docNode);
TemplateNodeModel docNodeModel = NodeModel.wrap(docNode);
HashMap root = new HashMap();
root.put("document", document);
// do your thing, return a loaded xml document
}
}
.... then, in your code where you do a transformation, simply create an
instance of Helper and add it to the FreeMarker context and transform?
Would this then allow the syntax in the template of
<#assign newdoc=$helper.load($base, $.node.Child.xmlfrag) />
${newdoc.somenode.@someattrib}
Would it work like so, or no?
Thanks, Russ
|