tag:help-archives.hannonhill.com,2010-02-09:/discussions/how-do-i/15804-sort-content-based-on-the-date-created-meta-dataCascade CMS: Discussion 2015-01-09T17:04:05Ztag:help-archives.hannonhill.com,2010-02-09:Comment/356933452015-01-05T14:49:21Z2015-01-05T14:49:41Zsort content based on the date created meta data<div><p>Hi Matthew,</p>
<p>If you are using an XSLT Format, you can sort by using
<code><xsl:sort></code> and selecting the <em>created-on</em>
element as the node to sort on. More information on sorting can be
<a href="http://www.w3schools.com/xsl/el_sort.asp">found
here</a>.</p>
<p>For example, your Format could have something like the
following:</p>
<pre>
<code><xsl:apply-templates select="system-symlink">
<xsl:sort select="created-on" order="ascending" />
</xsl:apply-templates></code>
</pre>
<p>If you are using Velocity, you can sort by XML elements using
the <a href=
"http://www.hannonhill.com/kb/Script-Formats/#sort-tool">Sort
Tool</a>. So your Format could have something like the
following:</p>
<pre>
<code>#set($links = $_XPathTool.selectNodes($contentRoot, '//system-symlink'))
$_SortTool.addSortCriterion("created-on", "", "number", "ascending", "upper-first")
$_SortTool.sort($links)</code>
</pre>
<p>Please let me know if you have any questions.</p>
<p>Thanks!</p></div>Ryan Griffithtag:help-archives.hannonhill.com,2010-02-09:Comment/356933452015-01-05T14:56:25Z2015-01-05T14:56:25Zsort content based on the date created meta data<div><p>I currently do not have a format in place so if I wanted to use
either one of these could I just created a format and paste one of
these in or would I have to do something else to utilize the sort
function?</p></div>matthew.wrentag:help-archives.hannonhill.com,2010-02-09:Comment/356933452015-01-05T15:26:08Z2015-01-05T15:26:08Zsort content based on the date created meta data<div><p>Hi Matthew,</p>
<p>Both examples should work out of the box, but you will still
need to loop over the sorted links and output what you need.</p>
<p>Additionally, for the XSLT sample, you would need to add an
<code><xsl:template></code> that matches the appropriate
elements.</p>
<p>Please let me know if you have any questions.</p>
<p>Thanks!</p></div>Ryan Griffithtag:help-archives.hannonhill.com,2010-02-09:Comment/356933452015-01-05T15:32:19Z2015-01-05T15:32:19Zsort content based on the date created meta data<div><p>I went with the Velocity because I like how succinct it is but
the output it generates (as is) is just blank xml</p>
<p><code><xml></xml></code></p>
<p>Another question I have is what kind of variable is that within
the <code><created-on></code> data? It seems like a string of
random numbers but is it some sort of time/date/year numbering
system?</p></div>matthew.wrentag:help-archives.hannonhill.com,2010-02-09:Comment/356933452015-01-05T20:24:09Z2015-01-05T20:24:09Zsort content based on the date created meta data<div><p>Hi Matthew,</p>
<p>When you have a moment, please attach your Velocity Format so we
can take a closer look at were you are at.</p>
<blockquote>
<p>Another question I have is what kind of variable is that within
the data? It seems like a string of random numbers but is it some
sort of time/date/year numbering system?</p>
</blockquote>
<p>The integer values for metadata such as created-on,
last-published, etc are unix timestamps. These timestamps contain
milliseconds, which is why there are 13 digits as opposed to the 10
you may encounter elsewhere like in PHP.</p>
<p>Please let me know if you have any questions.</p>
<p>Thanks!</p></div>Ryan Griffithtag:help-archives.hannonhill.com,2010-02-09:Comment/356933452015-01-05T20:43:04Z2015-01-05T20:43:04Zsort content based on the date created meta data<div><p>my format is just what you provided to me earlier so it's</p>
<pre>
<code>#set($links = $_XPathTool.selectNodes($contentRoot, '//system-symlink'))
$_SortTool.addSortCriterion("created-on", "", "number", "ascending", "upper-first")
$_SortTool.sort($links)</code>
</pre>
<p>Oh okay great, that's good to know!</p></div>matthew.wrentag:help-archives.hannonhill.com,2010-02-09:Comment/356933452015-01-05T20:47:29Z2015-01-05T20:47:29Zsort content based on the date created meta data<div><p>Hi Matthew,</p>
<p>As I mentioned previously, my sample only does the sorting and
you will still need to loop over the sorted links and output what
you need. For example:</p>
<pre>
<code>#set($links = $_XPathTool.selectNodes($contentRoot, '//system-symlink'))
$_SortTool.addSortCriterion("created-on", "", "number", "ascending", "upper-first")
$_SortTool.sort($links)
#if ($links.size() > 0)
#foreach ($link in $links)
### ... Do something with the `<system-symlink>` Element ...
#end
#end</code>
</pre>
<p>Please let me know if you have any questions.</p>
<p>Thanks!</p></div>Ryan Griffith