tag:help-archives.hannonhill.com,2010-02-09:/discussions/velocity-formats/37-sort-tool-last-published-onCascade CMS: Discussion 2018-10-18T20:36:17Ztag:help-archives.hannonhill.com,2010-02-09:Comment/81664032011-06-25T04:04:57Z2011-06-25T04:04:57ZSort Tool: last-published-on<div><p>Can you attach a sample of XML data that this format is
processing as well as the HTML outcome you're getting as
output?</p></div>Charlie Holdertag:help-archives.hannonhill.com,2010-02-09:Comment/81664032011-06-28T17:30:10Z2011-06-28T17:30:49ZSort Tool: last-published-on<div><p>Sure.<br>
You'll notice the System Pages are correctly in chronological order
(correctly) but then start repeating: <a href=
"http://union.edu/_dev8080/reports/recently-published/standard-content/">
http://union.edu/_dev8080/reports/recently-published/standard-content/</a></p>
<p>It's running against an index block (content type) which I've
attached. I also attached an updated version of the Velocity script
with comments.</p>
<p>Thanks for your help.</p></div>espanaetag:help-archives.hannonhill.com,2010-02-09:Comment/81664032011-07-03T18:26:37Z2011-07-03T18:28:32ZSort Tool: last-published-on<div><p>Oh man. This one was tricky to diagnose.</p>
<p>I don't really know why nor do I understand the implications
inside Cascade, but not all of the <code>system-page</code> nodes
contained in your sample XML have a <code>last-published-on</code>
node. I think that because the Velocity Format can't find the node
to sort on with the <code>$_SortTool</code> call some weird stuff
is happening. I'm sorry I personally cannot offer some more
concrete advice. I will bump this thread to support for an internal
discussion and then maybe they can offer something more
detailed.</p>
<p>With all that said, I was able to achieve a properly sorted page
by adding a filter to the initial <code>$_XPathTool</code> call.
The filter only includes pages that have a
<code>last-published-on</code> node.</p>
<p>I also made one (small) additional change to the Format. Instead
of having the #if statement inside your #foreach loop, you can
filter out the pages that belong to the "development" Site in the
initial <code>$_XPathTool</code> call similar to the previous
paragraph.</p>
<p>Here's a copy of the Format I ended with. Please let me know if
you have any questions.</p>
<pre>
<code>## // Get all System-Pages sorted by date published.
#set ( $sys_pages = $_XPathTool.selectNodes($contentRoot, "/system-index-block/system-page[last-published-on][is-published='true'][site!='development']") )
$_SortTool.addSortCriterion("last-published-on", "", "number", "descending", "")
$_SortTool.sort($sys_pages)
## // Style the table with CSS
<style>
thead th { text-align: center; font-weight: bold; }
td th { margin-left: 10px; margin-right: 10px; }
</style>
## // Table headers
<table style="width:900px;">
<thead>
<tr>
<th>Last Published Date</th>
<th>Last Published By</th>
<th>Link</th>
</tr>
</thead>
## // For each System Page, create a table row
#foreach ( $page in $sys_pages )
#set ( $by = $page.getChild("last-published-by").value )
#set ( $on = $page.getChild("last-published-on").value )
<tr>
<td>$_DateTool.format("MM/dd/yy hh:mm:ss a", $_DateTool.getDate($on))</td>
<td>
#if ( $by != "" ) ${by} #else N/A #end
</td>
<td>
<a href="${page.getChild("link").value}">
${page.getChild("path").value}
</a>
</td>
</tr>
#end
## // Close the table tag
</table></code>
</pre></div>Charlie Holdertag:help-archives.hannonhill.com,2010-02-09:Comment/81664032011-07-05T15:06:30Z2011-07-05T15:06:30ZSort Tool: last-published-on<div><p>Charlie, thank you for resolving the issue.<br>
I'll keep you posted if I notice any other "weirdness" with our
data.</p></div>espanae