Re: [FreeMarker-user] freemarker xml/xslt functions
Generates text that depends on changing data (like dynamic HTML).
Brought to you by:
revusky
|
From: Daniel D. <dd...@fr...> - 2005-12-22 00:00:27
|
Wednesday, December 21, 2005, 10:42:13 PM, Russell Simpkins wrote:
>>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);
Why do you modify the root? Just return it. It will be the value of an
method call expression.
> // 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) />
Without the $-s... it's like Java, you see.
> ${newdoc.somenode.@someattrib}
> Would it work like so, or no?
Something like this. BTW the commonly used "tools" can added at the
Configuration level, using yourConfiguration.setSharderVariable(...).
> Thanks, Russ
--
Best regards,
Daniel Dekany
|