tag:help-archives.hannonhill.com,2010-02-09:/discussions/velocity-formats/66-sort-on-multiple-criteriaCascade CMS: Discussion 2018-10-18T20:36:26Ztag:help-archives.hannonhill.com,2010-02-09:Comment/118940312011-12-05T16:34:34Z2011-12-05T16:34:34ZSort on multiple criteria<div><p>If you want to filter your results as part of your XPath query,
you can always add more criteria using an <code>and</code>
clause:<br>
<code>#set ($items = $_XPathTool.selectNodes($contentRoot,
"/system-index-block/system-page[system-data-structure[category =
'Class' and node = 'value']]"))</code></p>
<p>If you're looking to sort your actual returned pages, you can
use the <code>$_SortTool</code> and multiple <a href=
"http://www.hannonhill.com/kb/Script-Formats/#sort-tool">addSortCriterion()</a>
methods to order the returned pages that meet the criteria in your
XPath query.</p>
<p>I hope this helps. Let me know!</p></div>Charlie Holdertag:help-archives.hannonhill.com,2010-02-09:Comment/118940312011-12-07T16:17:23Z2011-12-07T16:23:24ZSort on multiple criteria<div><p>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.<br>
I tried this:<br>
<code>#set ($folderPages = $_XPathTool.selectNodes($contentRoot,
"/system-index-block/system-folder/system-page[system-data-structure[category
= 'Class' and node != 'index']]"))</code></p>
<p>Any insight on what I need to change? I'd rather filter the
results in the query, than sort the actual returned pages.</p>
<p>But still nothing is displaying.</p></div>lauren.frasertag:help-archives.hannonhill.com,2010-02-09:Comment/118940312011-12-07T16:26:30Z2011-12-07T16:26:30ZSort on multiple criteria<div><p>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.</p>
<p>Hopefully that makes sense.</p>
<p>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.</p></div>Charlie Holdertag:help-archives.hannonhill.com,2010-02-09:Comment/118940312011-12-07T16:37:00Z2011-12-07T16:37:00ZSort on multiple criteria<div><p>Hmmm. Changed 'node' to 'name' and still no data returned.</p>
<p>I've attached some xml and a small screenshot of what we're
trying to accomplish.<br>
It would also be nice if we could display the folder names as a
header, then list the classes underneath, like so:<br>
CPR:<br>
Family & Friends CPR (read more link)<br>
Healthcare Provider CPR (read more link)<br>
etc.</p></div>lauren.frasertag:help-archives.hannonhill.com,2010-02-09:Comment/118940312011-12-14T02:44:16Z2011-12-14T02:44:16ZSort on multiple criteria<div><p>Does this give you anything?</p>
<pre>
<code>#set ( $folderPages = $_XPathTool.selectNodes($contentRoot, "/system-index-block/system-folder/system-page[name!='index' and system-data-structure[category='Class']]") )</code>
</pre></div>Charlie Holdertag:help-archives.hannonhill.com,2010-02-09:Comment/118940312011-12-14T13:31:47Z2011-12-14T13:31:47ZSort on multiple criteria<div><p>Charlie,<br>
That worked just like I was hoping. Thanks!</p></div>lauren.frasertag:help-archives.hannonhill.com,2010-02-09:Comment/118940312011-12-14T13:59:01Z2011-12-14T13:59:01ZSort on multiple criteria<div><p>Yeah so the issue was with the location of the nodes you were
filtering on. Initially you were trying to filter based on the
<code>category</code> in the <code>system-data-structure</code> and
the <code>name</code> of the <code>system-page</code>. 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.</p>
<p>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.</p>
<p>You'd also have to update all the formats to be something
like:</p>
<pre>
<code>#set ( $folderPages = $_XPathTool.selectNodes($contentRoot, "/system-index-block/system-folder/system-page[name!='index' and dynamic-metadata[name='category' and value='Class']]") )</code>
</pre>
<p>Just something to think about. Glad I could help.</p></div>Charlie Holdertag:help-archives.hannonhill.com,2010-02-09:Comment/118940312012-03-28T16:57:45Z2012-03-28T17:13:08ZSort on multiple criteria<div><p>Charlie,<br>
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."</p>
<pre>
<code>#set ($items = $_XPathTool.selectNodes($contentRoot, "/system-index-block/system-folder/system-page[system-data-structure[category = 'Class' or 'Internal Events - CMH Employees Only']]"))</code>
</pre>
<p>Would this be easier if I switched the Category to a Dynamic
Metadata field?</p></div>lauren.frasertag:help-archives.hannonhill.com,2010-02-09:Comment/118940312012-03-28T17:19:17Z2012-03-28T17:19:17ZSort on multiple criteria<div><p>You can filter the events just fine as is.</p>
<p>Try:</p>
<pre>
<code>#set ($items = $_XPathTool.selectNodes($contentRoot, "/system-index-block/system-folder/system-page[system-data-structure[category = 'Class' or category = 'Internal Events - CMH Employees Only']]"))</code>
</pre>
<p>See the difference? You'll want to name the category node BOTH
times you need to test for a possible value.</p>
<p>Let me know if that works!</p></div>Charlie Holdertag:help-archives.hannonhill.com,2010-02-09:Comment/118940312012-04-03T22:56:42Z2012-04-03T22:56:42ZSort on multiple criteria<div><p>Thanks Charlie. Worked perfectly!</p></div>lauren.fraser