Sort on multiple criteria

lauren.fraser's Avatar

lauren.fraser

05 Dec, 2011 04:24 PM

I'm currently using a folder index to create a "course catalog" for our 2012 classes. I have the folder indexing and rendering correctly using a folder index block and a simple script that calls the folder page:
#set ($folderPages = $_XPathTool.selectNodes($contentRoot, "//system-page[name != 'index'] "))

In our data definition, users can choose: class, event, meeting, etc. I'd like to add a sort to the format so it will only display classes. I'm attaching the format and a screen shot that shows the "category" we'd like to sort on.

We previously had a different set up for the course catalog, where we used a content index then sorted on the category in the system data structure, like below:
#set ($items = $_XPathTool.selectNodes($contentRoot, "/system-index-block/system-page[system-data-structure[category = 'Class']]"))

We could continue using this format, if there was a way to sort by the date, so the page only displays 2012 classes.

Thanks in advance for any help.

  1. Support Staff 2 Posted by Charlie Holder on 05 Dec, 2011 04:34 PM

    Charlie Holder's Avatar

    If you want to filter your results as part of your XPath query, you can always add more criteria using an and clause:
    #set ($items = $_XPathTool.selectNodes($contentRoot, "/system-index-block/system-page[system-data-structure[category = 'Class' and node = 'value']]"))

    If you're looking to sort your actual returned pages, you can use the $_SortTool and multiple addSortCriterion() methods to order the returned pages that meet the criteria in your XPath query.

    I hope this helps. Let me know!

  2. 3 Posted by lauren.fraser on 07 Dec, 2011 04:17 PM

    lauren.fraser's Avatar

    Thanks for the quick reply Charlie. When I used the XPath query you listed above, I wasn't getting anything to display. I thought I might need to call the system folder, since the folder that is indexed has several sub folders.
    I tried this:
    #set ($folderPages = $_XPathTool.selectNodes($contentRoot, "/system-index-block/system-folder/system-page[system-data-structure[category = 'Class' and node != 'index']]"))

    Any insight on what I need to change? I'd rather filter the results in the query, than sort the actual returned pages.

    But still nothing is displaying.

  3. Support Staff 4 Posted by Charlie Holder on 07 Dec, 2011 04:26 PM

    Charlie Holder's Avatar

    In my example code I used the word 'node' because I wasn't 100% sure what your full criteria was. You'll probably want to replace the word 'node' with the actual name of the XML element your testing the value of 'index' to be not equal to.

    Hopefully that makes sense.

    If you still aren't able to achieve your final result, would you mind posting a sample of XML data as an attachment so that I can pull it into a local instance and play around? Also provide a sample of the desired end result. I may be able to help narrow down any other issues we are overlooking.

  4. 5 Posted by lauren.fraser on 07 Dec, 2011 04:37 PM

    lauren.fraser's Avatar

    Hmmm. Changed 'node' to 'name' and still no data returned.

    I've attached some xml and a small screenshot of what we're trying to accomplish.
    It would also be nice if we could display the folder names as a header, then list the classes underneath, like so:
    CPR:
    Family & Friends CPR (read more link)
    Healthcare Provider CPR (read more link)
    etc.

  5. Support Staff 6 Posted by Charlie Holder on 14 Dec, 2011 02:44 AM

    Charlie Holder's Avatar

    Does this give you anything?

    #set ( $folderPages = $_XPathTool.selectNodes($contentRoot, "/system-index-block/system-folder/system-page[name!='index' and system-data-structure[category='Class']]") )
    
  6. 7 Posted by lauren.fraser on 14 Dec, 2011 01:31 PM

    lauren.fraser's Avatar

    Charlie,
    That worked just like I was hoping. Thanks!

  7. Support Staff 8 Posted by Charlie Holder on 14 Dec, 2011 01:59 PM

    Charlie Holder's Avatar

    Yeah so the issue was with the location of the nodes you were filtering on. Initially you were trying to filter based on the category in the system-data-structure and the name of the system-page. Those two fields are at different levels in the XML data set. So it was just making sure that the filter matched the proper structure.

    As a side note, think about using the Category field as a Dynamic Metadata field (either custom checkbox, radio, or dropdown would work best). You would no longer have to include the Page XML (the system-data-structure), making your block run significantly faster. I know it's a big transition, but depending on how many places this block is being used (every page in your site?), you could save your system a great deal of processing time. That's an entire page worth of content that is being loaded into the XML data and not being used every single time the page loads inside of Cascade Server for every user.

    You'd also have to update all the formats to be something like:

    #set ( $folderPages = $_XPathTool.selectNodes($contentRoot, "/system-index-block/system-folder/system-page[name!='index' and dynamic-metadata[name='category' and value='Class']]") )
    

    Just something to think about. Glad I could help.

  8. Charlie Holder closed this discussion on 14 Dec, 2011 01:59 PM.

  9. lauren.fraser re-opened this discussion on 28 Mar, 2012 04:57 PM

  10. 9 Posted by lauren.fraser on 28 Mar, 2012 04:57 PM

    lauren.fraser's Avatar

    Charlie,
    I'm working on a second course catalog for our employees. Currently for the general public we use the Category to filter out just the pages marked as "Class." We use "Internal Events - CMH Employees Only" for internal trainings, etc. I'd like to use the format and index block we have above but have it show/output classes and internal events. I tried this, but it just displays all of the pages within the folder, regardless of their "Category."

    #set ($items = $_XPathTool.selectNodes($contentRoot, "/system-index-block/system-folder/system-page[system-data-structure[category = 'Class' or 'Internal Events - CMH Employees Only']]"))
    

    Would this be easier if I switched the Category to a Dynamic Metadata field?

  11. Support Staff 10 Posted by Charlie Holder on 28 Mar, 2012 05:19 PM

    Charlie Holder's Avatar

    You can filter the events just fine as is.

    Try:

    #set ($items = $_XPathTool.selectNodes($contentRoot, "/system-index-block/system-folder/system-page[system-data-structure[category = 'Class' or category = 'Internal Events - CMH Employees Only']]"))
    

    See the difference? You'll want to name the category node BOTH times you need to test for a possible value.

    Let me know if that works!

  12. 11 Posted by lauren.fraser on 03 Apr, 2012 10:56 PM

    lauren.fraser's Avatar

    Thanks Charlie. Worked perfectly!

  13. lauren.fraser closed this discussion on 03 Apr, 2012 10:56 PM.

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