scripting help
I have a data definition which allows input of listings of professional experience. I'm accessing it thusly:
#set ($experiences = $_XPathTool.selectNodes($contentRoot,
"/system-index-block/calling-page/system-page/system-data-structure/experience/listing"))
And with entries it displays nicely in format. What I want to do is, if no listings are entered, to have no display at all. What I'm trying is this:
#if ($experiences.size() > 0)
<h3>Professional Experience</h3>
` <ul>`
#foreach ($experience in $experiences)
` <li>$_SerializerTool.serialize($experience, true)`
` </li>`
`#end`
</ul>
#else #end
What I find is if no listing is made, it still prints the H3 heading with an empty bullet below. An example xml page is attached.
What have I missed?
- xml-eg.xml 926 Bytes
Discussions are closed to public comments.
If you need help with Cascade CMS please
start a new discussion.
Keyboard shortcuts
Generic
? | Show this help |
---|---|
ESC | Blurs the current field |
Comment Form
r | Focus the comment reply box |
---|---|
^ + ↩ | Submit the comment |
You can use Command ⌘
instead of Control ^
on Mac
1 Posted by Shiv on Aug 26, 2011 @ 03:21 PM
Well, $experiences.size is greater than zero -- there is one /system-index-block/calling-page/system-page/system-data-structure/experience/listing node, even though it's empty. So, $experiences.size() = 1.
You could first check the value of the first found node. If it's empty, do nothing.
2 Posted by Charlie Holder on Aug 26, 2011 @ 03:31 PM
Alternatively you could add a filter to your XPath statement to only select non-empty listing nodes.
#set ($experiences = $_XPathTool.selectNodes($contentRoot, "/system-index-block/calling-page/system-page/system-data-structure/experience[listing!='']/listing"))
3 Posted by Shiv on Aug 26, 2011 @ 03:34 PM
Charlie's answer is better than mine.
4 Posted by steelej on Aug 26, 2011 @ 03:40 PM
I knew I was picking up an empty node but didn't know the syntax to restrict to non-empty.
Your fix worked great Charlie. Thanks.
steelej closed this discussion on Aug 26, 2011 @ 03:40 PM.