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-21 18:33:05
|
Wednesday, December 21, 2005, 5:42:17 PM, Russell Simpkins wrote:
> Hello all.
>
> I am sick of xslt. I have managed to use digester to convert my XML to POJO
> to use Velocity on the frontend. I could just use freemarker the same way. I
> just started looking at freemarker, and I love the XML support. Sooooo much
> better than anakia. It looks like I could skip the digester -> pojo part
> too.
>
> I have made great use of the document function in my xslt and am having
> trouble doing document() in FreeMarker. I just started with the ant task
> (maybe that is the problem) and altered the supplied template example as
> such:
>
> <#assign
> loaded=.node['document("file:///java/freemarker-2.3.4/examples/ant/xml/faq.xml")']>
>
> The intent is that loaded is now the same as .node just as a proof of
> concept. This does not work, I get
>
> freemarker.template.TemplateModelException: org.jaxen.FunctionCallException:
> Failed to parse document for URI: file://c:/java/projects/acms/src/fro
> nt-end/home.xml
> at
> freemarker.ext.dom.JaxenXPathSupport.executeQuery(JaxenXPathSupport.java:120)
> at freemarker.ext.dom.NodeModel.get(NodeModel.java:279)
> at freemarker.ext.dom.DocumentModel.get(DocumentModel.java:93)......
>
> What am I doing wrong?
At the first glance it appears to me that Jaxen has a problem, not
FreeMarker. (You should use Jaxen 1.1 if you don't... lot of things was
fixed there.)
> How best to accomplish this?
This is rather just matter of taste, but I prefer to load XML-s with FTL
methods (functions). Like, if you look at FMPP, it has a generic
pp.loadData(...) method that can load data from various data source,
including XML-s. So it doesn't depend on XPath, also it can have various
wrapping related parameters.
> I'm using Jaxen-full and dom4j-1.4
>
> As background, I have a cms that produces lots of XML, and to keep the size
> of the XML down, I have broken up my XML into smaller files and then include
> references to those files in one XML.
> Sort of like this:
> <Page>
> <editpage>/edit/editPage.jsp?page_id=1</editpage>
> <pageId external="false" id="true" type="long"
maxlength="12">><![CDATA[1]]></pageId>
> <title external="false" id="false" type="java.lang.String"
maxlength="100">><![CDATA[homepage]]></title>
> <htmlTitle external="false" id="false" type="java.lang.String"
maxlength="250">><![CDATA[]]></htmlTitle>
> <keywords external="false" id="false" type="java.lang.String"
maxlength="1000">><![CDATA[]]></keywords>
> <description external="false" id="false" type="java.lang.String"
maxlength="3000">><![CDATA[]]></description>
> <Flashs>
> <Flash row="0" id="1" type="controller"
external="true">>/Flash/1/Flash.1.xml</Flash>
> </Flashs>
> <PageFlashs>
> <PageFlash row="0" id="1" external="true" start="" end=""
type="controller">>/PageFlash/1/PageFlash.1.xml</PageFlash>
> </PageFlashs>
> <Polls>
> <Poll row="0" id="17" type="opinion"
external="true">>/Poll/17/Poll.17.xml</Poll>
> <Poll row="1" id="18" type="opinion"
external="true">>/Poll/18/Poll.18.xml</Poll>
> <Poll row="2" id="14" type="opinion"
external="true">>/Poll/14/Poll.14.xml</Poll>
> <Poll row="3" id="15" type="opinion"
external="true">>/Poll/15/Poll.15.xml</Poll>
> </Polls>
> </Page>
> The paths are relative and the configuration of the web app passes in the
> base so that most XPath calls are like this:
> document(concat($xmlbase,$root/Polls/Poll[1]))
>
> Any help is appreciated. FYI: In the download, your build.xml for the ant
> task classpath ref, it is better suited to be written like so:
>
> <classpath>
> <fileset dir="${basedir}../../../lib">
> <include name="*.jar" />
> </fileset>
> </classpath>
>
> Then folks can just drop in their jar file if they want to, like i had to
> with my jaxen-full.jar and dom4j-1.4.jar
OK, I have fixed in the CVS. Except that I have omitted ${basedir}.
That's the default anyway, right?
--
Best regards,
Daniel Dekany
|