xxf:sort function

5 views
Skip to first unread message

Joel Oates

unread,
Jul 30, 2019, 1:31:10 AM7/30/19
to orb...@googlegroups.com
Hello,

I currently am trying to sort a list of objects inside an instance with the
xxf:sort function to sort the list based off a date inside the objects.

I have the following data

(code)
<xf:instance>
<activityDataWrapper>
<activityDataList>
<createdOn>2019-07-30T10:24:55+10:00</createdOn>
<id>63</id>
<info>
<documentationQueryInfo>
<id>63</id>
<request>My Request 1</request>
<response>test</response>
</documentationQueryInfo>
<id>63</id>
<requestor>joeladmin</requestor>
<responder>john</responder>
</info>
<state>Responded</state>
<type>DocumentQuery</type>
</activityDataList>
<activityDataList>
<createdOn>2019-07-30T13:30:43+10:00</createdOn>
<id>65</id>
<info>
<documentationQueryInfo>
<id>65</id>
<request>hello</request>
<response>sdfsdfsfsdfsdf</response>
</documentationQueryInfo>
<id>65</id>
<requestor>joeladmin</requestor>
<responder>CodingUser</responder>
</info>
<state>Responded</state>
<type>DocumentQuery</type>
</activityDataList>
<activityDataList>
<createdOn>2019-07-30T13:05:09+10:00</createdOn>
<id>64</id>
<info>
<documentationQueryInfo>
<id>64</id>
<request>temp</request>
<response>cooli</response>
</documentationQueryInfo>
<id>64</id>
<requestor>joeladmin</requestor>
<responder>john</responder>
</info>
<state>Responded</state>
<type>DocumentQuery</type>
</activityDataList>
</activityDataWrapper>
</xf:instance>
(code)

I am trying to sort this list of activityDataList entries by the createdOn
field which is a date.

I am trying to use the following code to sort the list

(code)
<xf:action ev:event="xforms-ready">
<xf:itemset ref="xxf:sort(instance(), activityDataList/createdOn,
'dateTime', 'ascending')"/>
</xf:action>
(code)

Following
https://doc.orbeon.com/xforms/xpath/extension-functions/extension-xml#xxf-sort
however I am not getting the desired result.

The result I am looking for the the activityDataList to be sorted into
Ascending order.

Any Idea to get my desired result?

Cheers,
Joel.

--
Sent from: http://discuss.orbeon.com/

Joel Oates

unread,
Jul 31, 2019, 12:21:19 AM7/31/19
to orb...@googlegroups.com
So an Update on this...

I have managed to get this working on a different field, I am currently
sorting on type with the following.

<xf:insert context=&quot;instance()&quot;
origin=&quot;&lt;b>xxf:sort(instance()/activityDataList, type, 'text',
'ascending')*"/>

however I still cannot get the date working correctly with

<xf:insert context="instance()"
origin="xxf:sort(instance()/activityDataList, createdOn, 'dateTime',
'ascending')"/>

What am I missing here?

Alessandro Vernet

unread,
Aug 1, 2019, 9:00:06 AM8/1/19
to orb...@googlegroups.com
Hi Joel,

I tried the exact same expression you had :), and got the error:

data-type on xsl:sort must be 'text' or 'number'

But if the timezone is the same on all your dates, using `text` works. Also,
the second argument is XPath but must be passed as a string. I will which
the documentation, which incorrectly says this must return an `item()`. This
gives us:

<xf:action event="xforms-ready">
<xf:insert
ref="instance()"
origin="
xxf:sort(
instance(),
'activityDataList/createdOn',
'text',
'ascending'
)"/>
</xf:action>

You'll let me know if this works for you.

‑Alex

-----
--
Follow Orbeon on Twitter: @orbeon
Follow me on Twitter: @avernet

Alessandro Vernet

unread,
Aug 4, 2019, 12:16:47 PM8/4/19
to orb...@googlegroups.com
Hi Joel,

Actually, my bad, the code should be:

<xf:insert
ref="instance()"
origin="
xf:element('activityDataWrapper',
xxf:sort(
instance()/activityDataList,
createdOn,
'text',
'ascending'
)
)
"/>

You'll let me know if this works for you this time!

And here is the source of a full example:
view.xhtml <http://discuss.orbeon.com/file/t119778/view.xhtml>

Joel Oates

unread,
Aug 10, 2019, 1:01:04 AM8/10/19
to orb...@googlegroups.com
Thanks Alex! this worked!

Alessandro Vernet

unread,
Aug 10, 2019, 5:30:37 PM8/10/19
to orb...@googlegroups.com
Perfect Joel, it can be tricky that `xxf:sort()` right, and thank you for the
update.

‑Alex

-----
--
Follow Orbeon on Twitter: @orbeon
Follow me on Twitter: @avernet
Reply all
Reply to author
Forward
0 new messages