How do I use xpath to exclude a certain folder?

Eric's Avatar

Eric

25 Aug, 2014 07:36 PM

I have an index block with a bunch of different indexed pages in it.

I also have another page, a base asset -- I don't want that base-asset page to show up in that index block, but I want users to use this base asset to create new pages that will be indexed.

I keep this base asset page inside of a folder called "/_internal"

I suspect that the best way to "hide" this base asset page from the index block would be to exclude the "/_internal" folder in my XPath statement.

How would I exclude the "/_internal" folder with an Xpath statement in velocity?

  1. 1 Posted by Ryan Griffith on 25 Aug, 2014 07:59 PM

    Ryan Griffith's Avatar

    Hi Eric,

    You should be able to add the following to your XPath expression to make sure the _internal folder is not included:

    system-folder[not(contains(name, 'internal'))]
    

    Please let me know if you have any questions.

    Thanks!

  2. 2 Posted by Ryan Griffith on 25 Aug, 2014 08:00 PM

    Ryan Griffith's Avatar

    Er, my apologies, Eric, I meant to use path and not name:

    system-folder[not(contains(path, 'internal'))]
    

    Please let me know if you have any questions.

    Thanks!

  3. 3 Posted by Eric on 25 Aug, 2014 08:23 PM

    Eric's Avatar

    This is the entire line of code that contains my xpath statement:

    #set ( $exhibitions = $_XPathTool.selectNodes($contentRoot, "//system-page[dynamic-metadata[name='status' and value='Current'] [not(contains(path, '_internal'))]]") )
    
    • Is my syntax completely wrong? I am also using my xpath statement to select a dynamic meta-data set.
    • The folder name, "_internal" starts with an underscore. Is causing anything to be messed-up?

    I can't get it to work. I suspect that the syntax is wrong.

  4. 4 Posted by Ryan Griffith on 25 Aug, 2014 08:29 PM

    Ryan Griffith's Avatar

    Hi Eric,

    It looks like your XPath statement needs to be tweaked slightly. When you have a moment, give the following a try and let me know how it works out:

    //system-page[not(contains(path, '_internal')) and dynamic-metadata[name='status' and value='Current']]
    

    Please let me know if you have any questions.

    Thanks!

  5. 5 Posted by Eric on 25 Aug, 2014 08:32 PM

    Eric's Avatar

    Worked! Thank you. I am gaining a better understanding of xpath.

  6. 6 Posted by Ryan Griffith on 25 Aug, 2014 08:46 PM

    Ryan Griffith's Avatar

    Thank you for following up, Eric. I am glad to hear the new XPath did the trick.

    I'm going to go ahead and close this discussion, please feel free to comment or reply to re-open if you have any additional questions.

    Have a great day!

  7. Ryan Griffith closed this discussion on 25 Aug, 2014 08:46 PM.

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

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