Java Mailing List Archive

Home » FreeMarker-user »

Re: [FreeMarker-user] Difficulty with XPath and Namespaces using
 Eclipse with simple ANT build

Daniel Dekany


Replies: Find Java Web Hosting

Author LoginPost Reply
Monday, March 26, 2012, 5:19:48 PM, Robert Johnson wrote:

> <#list document["book/chapter[title='Ch1']/para"] as p>
>  <p>${p}
> </#list>
> As you can see, the XPath just doesn't return anything (nor any
> error)

(I does return something: the empty list of matching nodes. Otherwise
it would stop with an error.)

> and yet all this is a direct copy out of the documentation on-line.

The @ is missing before "title" in that XPath expression, so there are
0 matches... I will fix this in the docs.

> BUT, use this template
> <#ftl ns_prefixes={"e":""}>
> <#assign book=document["e:book"]>
> [freemarker] Mar 26, 2012 4:15:35 PM
> freemarker.log.JDK14LoggerFactory$JDK14Logger error
> [freemarker] SEVERE: Template processing error: "Namespace prefix e is not registered."
> [freemarker] Namespace prefix e is not registered.
> [freemarker] The problematic instruction:
> [freemarker] ----------
[freemarker] ==>> assignment: book=document["e:book"] [on line 2, column 1 in books.ftl]

This one works for me. The problem in your case seems to be that
"document" wasn't wrapped by the freemarker.ext.dom, but with
freemarker.ext.xml, which is a legacy wrapper that's not documented in
the Manual. If you are using
here, note the deprecation note that says not to use "document", but
".node". So either it should be <#assign book = .node["e:book"]>, or
you should start with <#assign document = .node>. That the Manual used
"document" is mere coincidence... it wasn't written with
FreemarkerXmlTask in mind, as the example itself doesn't use it

Best regards,
Daniel Dekany

This SF email is sponsosred by:
Try Windows Azure free for 90 days Click Here
FreeMarker-user mailing list
©2008 - Jax Systems, LLC, U.S.A.