Re: Generic template question

Daniel Dekany <[email protected]>
Newsgroups gmane.comp.web.freemarker.user
Message-ID <[email protected]>
Friday, February 20, 2009, 12:26:34 AM, Daniel Dekany wrote:
> Thursday, February 19, 2009, 9:56:49 PM, Kirill wrote:
[snip]
> Yes, you can. The key problem is problem is, #recurse doesn't attempt
> to visit attribute nodes (because W3C DOM doesn't treat attributes as
> children). But you can solve that like this:
>
>   <#macro recurseAttributes>
>     <#list .node["@*"] as att>
>       <#visit att>
>     </#list>
>   </#macro>

Only problem is, that if you have elements and attributes with the
same name, then the handler macro names will conflict... /-: That
still could be solved if you put the attribute handler(s) in another
template and use the 2nd parameter of #visit... but that would be just
too awkward. So instead you can directly call a handler macro... but
then remember, .node will point to the current element in that macro.

  <#macro recurseAttributes>
    <#list .node["@*"] as att>
      <@@attribute att />
    </#list>
  </#macro>

  <#macro @attribute att>
    ATT: I'm the ${att?node_name} attribute
         of an ${.node?node_name} element.
         I'm belonging to the ${att?node_namespace!'void'} namespace.
         My value is: ${att}
  </#macro>


-- 
Best regards,
 Daniel Dekany


------------------------------------------------------------------------------
Open Source Business Conference (OSBC), March 24-25, 2009, San Francisco, CA
-OSBC tackles the biggest issue in open source: Open Sourcing the Enterprise
-Strategies to boost innovation and cut costs with open source participation
-Receive a $600 discount off the registration fee with the source code: SFAD
http://p.sf.net/sfu/XcvMzF8H
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.