Hoping this is some easy karma for someone (@LeeKelleher??)
I am trying to make an XPath checkbox list datatype that contains all nodes of type 'Person' - but in reverse oder. (equally I could order by create date but don't think that is doable in XPath?)
I have tried variations of
reverse(//Person)
but I am getting a syntax error - is that because the reverse function is only in XPath 2.0?
As a workaround is there a way to compare a date property in the Person nodes to the current date? So I could restrict the list based on a time period?
You could do that with a little hack - suppose you have a node somewhere with a currentDate property on it, that you knew would be kind of updated regularly.
Replace $currentPage with what's the optimal for your context, and likewise with /root/somenodepath/currentDate :-)
(The trick involves converting the date strings to effectively numbers by stripping all non-digits, since you can't compare dates or strings in any meaningful way in XSLT 1.0)
As far as I'm aware you can't sort the node-set within the XPath expression itself, (although Chriztian's suggestion looks very interesting!)
Is this just for the XPath CheckBoxList data-type? It would be possible to change the sort order of the node-set after the XPath has done it's "thing".
We could add an option in the settings, e.g. "Reverse sort order?" But then that would only be sorted on the node's Id or Name, (not a custom property).
Hi Lee, thanks for chipping in - Chriztian's workaround has worked for me in this instance so that is fine. Not sure about adding extra options to the XPath CheckBoxList data-type, it would be handy to control the order of items but might also make it a bit more confusing generally.
What would be cool though, when the concept of Container Document Types sees the light of day:
To integrate a new (picker) data type with this somehow so the list of items can reflect the settings of its container. Or another option, if there was a way to change the default order of child nodes from a parent (e.g. most recent first) - that the XPath CheckBoxList data-type would respect that order (I guess it would anyway)?
@Lee: I could see some pretty cool scenarios if you could just enter an XPath to sort by, e.g. @createDate or count(*[@isDoc]) and then be able to tick DESC as the sort order...
XPath reverse list order
Hoping this is some easy karma for someone (@LeeKelleher??)
I am trying to make an XPath checkbox list datatype that contains all nodes of type 'Person' - but in reverse oder. (equally I could order by create date but don't think that is doable in XPath?)
I have tried variations of
but I am getting a syntax error - is that because the reverse function is only in XPath 2.0?
Suggestions and workarounds most welcome, thanks
Hi Barry,
Yeah, you can't do that in a single XPath (1.0) expression - that is something they'd need to add as a special "sort" feature or similar.
/Chriztian
Thanks Chriztian, thought that might be the case.
As a workaround is there a way to compare a date property in the Person nodes to the current date? So I could restrict the list based on a time period?
Hi Barry,
You could do that with a little hack - suppose you have a node somewhere with a currentDate property on it, that you knew would be kind of updated regularly.
Then you could say:
Replace $currentPage with what's the optimal for your context, and likewise with /root/somenodepath/currentDate :-)
(The trick involves converting the date strings to effectively numbers by stripping all non-digits, since you can't compare dates or strings in any meaningful way in XSLT 1.0)
/Chriztian
Hi Barry,
As far as I'm aware you can't sort the node-set within the XPath expression itself, (although Chriztian's suggestion looks very interesting!)
Is this just for the XPath CheckBoxList data-type? It would be possible to change the sort order of the node-set after the XPath has done it's "thing".
We could add an option in the settings, e.g. "Reverse sort order?" But then that would only be sorted on the node's Id or Name, (not a custom property).
If you think we should add it in, open a ticket on the issue tracker - we'll schedule it in: http://issues.umbraco.org/issues#newissue=yes
Cheers, Lee.
Hi Lee, thanks for chipping in - Chriztian's workaround has worked for me in this instance so that is fine. Not sure about adding extra options to the XPath CheckBoxList data-type, it would be handy to control the order of items but might also make it a bit more confusing generally.
What would be cool though, when the concept of Container Document Types sees the light of day:
http://our.umbraco.org/contribute/releases/4100/rfc/33203-Container-Document-Types
To integrate a new (picker) data type with this somehow so the list of items can reflect the settings of its container. Or another option, if there was a way to change the default order of child nodes from a parent (e.g. most recent first) - that the XPath CheckBoxList data-type would respect that order (I guess it would anyway)?
@Lee: I could see some pretty cool scenarios if you could just enter an XPath to sort by, e.g. @createDate or count(*[@isDoc]) and then be able to tick DESC as the sort order...
(pondering ...)
/Chriztian
is working on a reply...