hi all,
im using xpath to return some search results as an XML DOM. Now i need to implement a sorting function which would take any number of parameters and sort the results based on them.
Essentially the parameters will be tags in the xml docs like "Name" and "category" for now.
So heres an example of an output from my search
<data>
<block>
<name>Test Name 2</name>
<category>Category 2</category>
</block>
<block>
<name>a Simple test</name>
<category>Category 1</category
</block>
</data>
So if that was returned we can see that block 2 with the name "a simple test" is in position 2. I want to apply a sort that will move that into position one and return a new xml doc. I read how to transform XML with XSL and understand how to replace nodes and values, but lost trying to understand how to apply any kind of sorting.
Any help would be appreciated.
TIA,
mcm
PHP - Re-sorging XML doc with XSL
Moderator: General Moderators
- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
Re: PHP - Re-sorging XML doc with XSL
As I recall, there is not way to easily sort XML. I would convert the XML to an array, sort that, and then back to XML, then apply the XSL.
(#10850)
Re: PHP - Re-sorging XML doc with XSL
thanks for the tip.
im a dot net guy usually. with dot net we have data sets and data tables which are quite easy to sort. Is there anything like that in php? maybe i can put the xml into a dataset first, apply sorts and filters and then spit it back out to xml?
thanks,
mcm
im a dot net guy usually. with dot net we have data sets and data tables which are quite easy to sort. Is there anything like that in php? maybe i can put the xml into a dataset first, apply sorts and filters and then spit it back out to xml?
thanks,
mcm
- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
Re: PHP - Re-sorging XML doc with XSL
using php 4 <ugh>
thanks
mcm
thanks
mcm