Re: Sorting XML Nodes
Daniel Dekany <[email protected]>
| Newsgroups | gmane.comp.web.freemarker.user |
|---|---|
| Message-ID | <[email protected]> |
I think it's fair to blame `?sort_by` for this. And as always when there's no proper built-in for something that is not feasible to implement as an FTL #function, you should write a TemplateMethodModelEx for this in Java, pull it into an #import-ed/#included template with `?new` (or just put it into Configuration as shared variable), and then call it from the templates. Monday, September 19, 2011, 7:52:02 PM, Kirill wrote: > Hey there, > > I need to sort the XML tree based on one of its' nodes. > Let's say I have the following XML tree: > > <root> > <item id=1/> > <item id=2/> > <item id=3/> > <item id=10/> > <item id=11/> > </root> > > I've read that freemarker's sort_by built-in is pretty limited, > i.e. you cannot force the conversion of the sortable to number, for > example (so you can't do ?sort_by(["var1", "var2?number"])). > Now, when I do ?sort_by(["item","id"]), the result I get is this, of course: > > <root> > <item id=1/> > <item id=10/> > <item id=11/> > <item id=2/> > <item id=3/> > </root> > > My question is this - how can I emulate the natural sort order of > the list, by modifying id variables in the original XML? > I have full control of the original XML and can modify any values (add string/digits, etc)? > > Any ideas? > > Thanks much, > Kirill -- Best regards, Daniel Dekany ------------------------------------------------------------------------------ All the data continuously generated in your IT infrastructure contains a definitive record of customers, application performance, security threats, fraudulent activity and more. Splunk takes this data and makes sense of it. Business sense. IT sense. Common sense. http://p.sf.net/sfu/splunk-d2dcopy1