You can certainly use the
XPath string functions to do a lot of the LIKE type of functionality. However, XPath itself does not provide sorting functionality. XPath itself does not provide for sorting capabilities, but you can achieve this using the .NET framework classes. Dan Wahlin
posted an example of using the XPathExpression class to sort documents.
Hi kaevans, 1. ::However, XPath itself does not provide sorting functionality. 1 question for clarification: Alternatively, how about element ? 2. See example of :
XML File (sortempl.xml)
Loni
Ota
Leonard
Zuvela
XSLT File (sortempl.xsl)
Where there is a will, there is a way.
and where there is a team, there is more than one way.
That is XSLT, not XPath. The original poster asked about XPath. As I said in the original response, XPath does not provide sorting. You have to use some other means to sort.
kaevans, ::That is XSLT, not XPath. The original poster asked about XPath. 100% agreed technically on wording. However, from the 'intention' point of view, the question may ask for a sort? :-D This is just an open-interpretation.
Where there is a will, there is a way.
and where there is a team, there is more than one way.
Just to provide alternatives, one could use .NET'as built-in XPath classes also. Here is a minor example. Assume we have XML like this:
kaevans
phuoc
mazdak
joteke
And we do as follows:
'Load XML data to XpathDocument
Dim xpathdoc As New XPathDocument(Server.MapPath("XMLFile1.xml"))
'Create XPathNavigator
Dim xnav As XPathNavigator = xpathdoc.CreateNavigator()
'Get compiled XpathExpression
Dim exp As XPathExpression = xnav.Compile("/fusers/fuser")
'Provide means for sorting
exp.AddSort(".", XmlSortOrder.Ascending, XmlCaseOrder.None, "fi-FI", XmlDataType.Text)
'Get results to XpathNodeIterator
Dim iter As XPathNodeIterator = xnav.Select(exp)
'Dispaly results
While iter.MoveNext
Response.Write(iter.Current.ToString() & " ")
End While
Result is (quite predictably): joteke kaevans mazdak phuoc And if we change the sort order to XmlSortOrder.Descending
it is of course: phuoc mazdak kaevans joteke
The code joteke used to sort the xml looks like vbscript, but when I dim an object as new XPathDocument, I get an error that Type XPathDocument is not defined. I'm using How do I get it to recognize XPathDocument in ASP.NET with vbscript?
Mazdak
Member
145 Points
29 Posts
XPath question
Aug 13, 2003 11:53 AM|LINK
kaevans
Participant
1150 Points
230 Posts
Microsoft
Re: XPath question
Aug 13, 2003 08:17 PM|LINK
Phuoc
Participant
1150 Points
230 Posts
Re: XPath question
Aug 13, 2003 08:26 PM|LINK
XML File (sortempl.xml) Loni Ota Leonard Zuvela XSLT File (sortempl.xsl)and where there is a team, there is more than one way.
kaevans
Participant
1150 Points
230 Posts
Microsoft
Re: XPath question
Aug 14, 2003 12:39 AM|LINK
Phuoc
Participant
1150 Points
230 Posts
Re: XPath question
Aug 14, 2003 12:49 AM|LINK
and where there is a team, there is more than one way.
joteke
All-Star
46284 Points
6896 Posts
ASPInsiders
MVP
Re: XPath question
Aug 14, 2003 05:53 AM|LINK
'Load XML data to XpathDocument Dim xpathdoc As New XPathDocument(Server.MapPath("XMLFile1.xml")) 'Create XPathNavigator Dim xnav As XPathNavigator = xpathdoc.CreateNavigator() 'Get compiled XpathExpression Dim exp As XPathExpression = xnav.Compile("/fusers/fuser") 'Provide means for sorting exp.AddSort(".", XmlSortOrder.Ascending, XmlCaseOrder.None, "fi-FI", XmlDataType.Text) 'Get results to XpathNodeIterator Dim iter As XPathNodeIterator = xnav.Select(exp) 'Dispaly results While iter.MoveNext Response.Write(iter.Current.ToString() & "Result is (quite predictably): joteke kaevans mazdak phuoc And if we change the sort order to XmlSortOrder.Descending it is of course: phuoc mazdak kaevans joteke") End While
Teemu Keiski
Finland, EU
Phuoc
Participant
1150 Points
230 Posts
Re: XPath question
Aug 14, 2003 02:15 PM|LINK
and where there is a team, there is more than one way.
kaevans
Participant
1150 Points
230 Posts
Microsoft
Re: XPath question
Aug 14, 2003 02:51 PM|LINK
joteke
All-Star
46284 Points
6896 Posts
ASPInsiders
MVP
Re: XPath question
Aug 14, 2003 04:57 PM|LINK
Teemu Keiski
Finland, EU
dottystorer
Member
10 Points
2 Posts
Re: XPath question
Aug 19, 2003 06:23 PM|LINK