These is my XML.
<root>
<element>
<title>Title .. </title>
<val>2</val>
<date>21/01/2011</date>
</element>
<element>
<title>Title .. </title>
<val>1</val>
<date>21/01/2011</date>
</element>
<element>
<title>Title .. </title>
<val>2</val>
<date>22/01/2011</date>
</element>
</root>
The logic is this: Element nodes should be ranked according to node val and date. First Order must be based on val and within this sequence of nodes with val value. They should be listed by date.
Does anyone know how to get a sorted list of XML nodes via XPath?
Any ideas?
You can use
xsl:sort
to sort matching nodes. This will allow you to sort by yourval
element. However, XPath 1.0 does not have a date data-type. A reasonable solution to this problemm is to split your date into its year, month and day components and sort by each individually. The following should do the trick:It seems that XPath 3.1 offers sorting:
Signatures
https://www.w3.org/TR/xpath-functions-31/#func-sort