cancel
Showing results for 
Search instead for 
Did you mean: 

How to sorting by using the content

creddy2001
Champ in-the-making
Champ in-the-making
How to sor the XML documents by using the content.

This is my sample XML file. In this xml there is an event_date. I want to sort all the documents by event_date using web scripts . Please help me out in resolving this isse. I am also giving my Java script and response template.

  <?xml version="1.0" encoding="UTF-8" ?>
- <upcoming_event:upcoming_event xmlns:alf="http://www.alfresco.org" xmlns:chiba="http://chiba.sourceforge.net/xforms" xmlns:ev="http://www.w3.org/2001/xml-events" xmlns:upcoming_event="http://www.alfresco.org/alfresco/upcoming_event" xmlns:xf="http://www.w3.org/2002/xforms" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <upcoming_event:event_date>2009-07-07</upcoming_event:event_date>
  <upcoming_event:title>"Notice of Intent" for the US Department of Transportation (USDOT) "Transportation Investments Generating Economic Recovery" (TIGER) Discretionary Grants Due to CalTrans</upcoming_event:title>
- <upcoming_event:image_details xsi:nil="true">
  <upcoming_event:image>/upcomingevents/images/deadline.gif</upcoming_event:image>
  <upcoming_event:caption xsi:nil="false">Deadline</upcoming_event:caption>
  </upcoming_event:image_details>
- <upcoming_event:event_details xsi:nil="true">
  <upcoming_event:url xsi:nil="true" />
  <upcoming_event:caption xsi:nil="true" />
  <upcoming_event:title xsi:nil="true" />
  <upcoming_event:description xsi:nil="false"><p>The "Notice of Intent" for the US Department of Transportation (USDOT) "Transportation Investments Generating Economic Recovery" (TIGER) Discretionary Grants is due from potential applicants to Caltrans. This notice requires that basic information be provided to the Department regarding the type of project, size, and funding. These notices will also provide an indication of the number of potential applicants. The Department will use the information to plan for the review teams that are needed to review the applications. These applications are due to be submitted to Caltrans on July 27, 2009. The applications must be submitted to the US Department of Transportation by September 15, 2009.</p></upcoming_event:description>
  </upcoming_event:event_details>
  </upcoming_event:upcoming_event>

Java Script
———————

script:
{
   var storeid = ("recoverywebsite");
   var path = ("/www/avm_webapps/ROOT/UpcomingEvents/source");
   
   var store = avm.lookupStore(storeid);
   if (store == undefined)
   {
     status.code = 404;
     status.message = "Store " + storeid + " not found.";
     status.redirect = true;
     break script;
   }
   var node = avm.lookupNode(storeid + ":" + path);
   if (node == undefined)
   {
     status.code = 404;
     status.message = "Path " + path + " within store " + storeid + " not found.";
     status.redirect = true;
     break script;
   }
   
   // setup model for templates
   model.store = store;
   model.folder = node;   
}

Response Template
————————

<#ftl ns_prefixes={"D":"http://www.alfresco.org/alfresco/upcoming_event"}>
<#list folder.children as document>
   <#if document.mimetype = "text/xml">
      <#assign dom=document.xmlNodeModel>   
      <tr>
         <#assign eventDate = (dom.upcoming_event.event_date?date("yyyy-MM-dd"))?string("MM/dd/yyyy")>
         <td style="vertical-align:top;">${eventDate}</td>
         <td style="vertical-align:top;align:center;"><img src="${dom.upcoming_event.image_details.image}" alt="${dom.upcoming_event.image_details.caption}" width="20" height="17" /></td>
         <td style="vertical-align:top;"><a href="upcomingevents.shtml#${document_index}">${dom.upcoming_event.title}</a></td>
      </tr>
   </#if>
</#list>

thanks
Chandra
3 REPLIES 3

lyamamot
Champ in-the-making
Champ in-the-making
If you can guarantee that the folder's children all have the 'text/xml' mimetype, you may be able to use Freemarker's "sort_by" built-in for sequences. In your FTL, where you have "<#list folder.children as document>", try:
<#list folder.children?sort_by['xmlNodeModel', 'upcoming_event', 'event_date'] as document>
Note that this assumes that the property "xmlNodeModel" exists on each child so as I said, if your child is not of type "text/xml" then this won't work.

Otherwise, I would just do the sorting in the JS and pass an already-sorted array to FreeMarker.

creddy2001
Champ in-the-making
Champ in-the-making
Thanks for your help lyamamot

As you  said Its working  if all  are XML docments in that folder.  please  can you give me the example to sort in JS.

I tried to sort in JS by verfying some examples, Its not throwing any error but not sorting.


Thanks
Chandra

creddy2001
Champ in-the-making
Champ in-the-making
I am able to sole this issue.

Thanks lyamamot for your time and suggestion to resolve this issue.


Thanks
Chandra