[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 16:42:24
|
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? How best to accomplish this? 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
Thanks again.
russ
|