Re: Difficulty with XPath and Namespaces using Eclipse with simple ANT build

Daniel Dekany <[email protected]>
Newsgroups gmane.comp.web.freemarker.user
Message-ID <[email protected]>
Monday, March 26, 2012, 5:19:48 PM, Robert Johnson wrote:

[snip]
> <#list document["book/chapter[title='Ch1']/para"] as p>
>   <p>${p}
> </#list>
[snip]
> 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.

[snip]
> BUT, use this template
>
> <#ftl ns_prefixes={"e":"http://example.com/ebook"}>
> <#assign book=document["e:book"]>
[snip]
> [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
http://freemarker.org/docs/api/freemarker/ext/ant/FreemarkerXmlTask.html
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
either.

-- 
Best regards,
 Daniel Dekany


------------------------------------------------------------------------------
This SF email is sponsosred by:
Try Windows Azure free for 90 days Click Here 
http://p.sf.net/sfu/sfd2d-msazure
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.