Xpath Child & Sibling value

Matt's Avatar


02 Jun, 2014 04:38 PM

I'm using the following XML pattern:
<system-folder id="12345"> <name>About_Us</name> <title>About Us</title> <dynamic-metadata> <name>display-in-navigation</name> <value>Yes</value> </dynamic-metadata> <dynamic-metadata> <name>display-in-sitemap</name> <value>Yes</value> </dynamic-metadata> </system-folder> I want to use Xpath to select these but I'm not sure how to filter so that the dynamic-metadata has the child name with a value of "display-in-navigation" and a sibling value node with "Yes".

The closest I've came is:
$_XPathTool.selectNodes($sib, "system-folder[ ( dynamic-metadata/name='display-in-navigation' ) and ( dynamic-metadata/value='Yes' ) ] )

Unfortunately since there are multiple dynamic-metadata/value nodes in the XML feed, it's possible that display-in-sitemap could be set to yes and display-in-navigation could be set to no. If this happens, my above fails.

  1. 1 Posted by Wing Ming Chan on 02 Jun, 2014 05:38 PM

    Wing Ming Chan's Avatar

    Hi Matt,

    Try this XPath expression:


    I only tested it with XSLT, not with Velocity. But I believe it'll work.


  2. 2 Posted by Ryan Griffith on 02 Jun, 2014 06:20 PM

    Ryan Griffith's Avatar

    Hi Matt,

    Wing's XPath looks spot on. One thing to keep in mind for checkbox and radio dynamic metadata fields, if no value is selected at all the value element will not be present. This XPath will work just fine by filtering only those with an actual value element that is equal to Yes, but just something to be aware of.

  3. 3 Posted by Wing Ming Chan on 02 Jun, 2014 06:25 PM

    Wing Ming Chan's Avatar


    Thank you for reminding us to test the value first:

    system-folder[dynamic-metadata[name='display-in-navigation']/value and dynamic-metadata[name='display-in-navigation']/value='Yes']


  4. 4 Posted by Ryan Griffith on 02 Jun, 2014 06:27 PM

    Ryan Griffith's Avatar

    Not a problem at all, Wing. I double-checked and confirmed that your original XPath worked as well if no item is checked.

  5. Ryan Griffith closed this discussion on 05 Jun, 2014 01:20 PM.

Comments are currently closed for this discussion. You can start a new one.

Keyboard shortcuts


? 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