Re: XMLProcessing : testing optional value in a NodeModel
Daniel Dekany <[email protected]>
| Newsgroups | gmane.comp.web.freemarker.user |
|---|---|
| Message-ID | <[email protected]> |
Tuesday, February 5, 2008, 5:49:14 PM, thierry.henrio wrote:
> Hi all,
>
> I would like to conditionaly provide xml section if some attributes exists
> in model
>
> here is my model
> <?xml version="1.0" encoding="UTF-8"?>
> <connection name="sle-001" template="sle-optional.ftl" saveDir="save">
> </connection>
>
> model is parsed using dom api and a NodeModel is made out of it
>
> here is my template
> <connections>
> <connection name="${connection.@name}" url="imc:gl:slev42">
> <#if (connection.@saveDir)??>
[snip]
The result of an expression like that is a node-set, as it can be not
only a single node but multiple nodes as well, or 0 nodes. It's just
like in XPath. Actually it's XPath syntactically ("@attName"). In the
case of FreeMarker (with this ObjectWrapper anyway), the node-set is
presented as a sequence of nodes. Thus the result itself is never
"missing", it's just possibly an empty sequence. So, you had to write
connection.@saveDir[0]??.
--
Best regards,
Daniel Dekany
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/