Freemarker XPath expression to find a node with a child id -


i'm using freemarker xml processing build menu. want find if current element, or of it's children have id matching activenode.

but i'm having lot of trouble working out freemarker syntax xpath. seems match nodes children links (note item node reference customers node)

<#assign anode="search-customers" /> <#assign xpath>link["@id=${anode}"]</#assign>  <#if item[xpath][0]?has_content>     <#assign cssclass> class="active"</#assign> </#if>   

this relevant section of xml i'm trying match. example, search-customers node, should highlight customers node.

<menu>     <top title="title.home" url="/admin" icon="fa fa-home" />     <top title="title.customers" id="customers" url="javascript:;" icon="fa fa-group">         <link title="title.search.customers" id="search-customers" url="/admin/customers"></link>         <link title="title.register.customer" id="register-customer" url="/admin/customers/new"></link>         <link title="title.contact.us" id="contact-us" url="/admin/contactus"></link>         <link title="title.subscribers" id="subscribers" url="/admin/subscribers"></link>     </top> 

ideally match current node id - css should active if either child node id, or current node id matches activenode.

can freemarker syntax this?

never mind, figured out eventually, think it's error in docs put me off using square bracket syntax....

<#if strval=anode || item["link[@id='${anode}']"]?has_content>     <#assign cssclass> class="active"</#assign> <#else>     <#assign cssclass></#assign> </#if> 

Comments

Popular posts from this blog

node.js - Mongoose: Cast to ObjectId failed for value on newly created object after setting the value -

gradle error "Cannot convert the provided notation to a File or URI" -

python - NameError: name 'subprocess' is not defined -