views:

832

answers:

3

I want to sort below xml, Based on the Adult and child ( i need to take Adult and child as constant):

<HotelDetails>
  <hotel>
    <rooms>
      <room>
        <roomname>Single</roomname> 
        <Price>100</Price> 
        <Adult>1</Adult> 
        <child>0</child> 
      </room>
    </rooms>
    <rooms>
      <room>
        <roomname>Single</roomname> 
        <Price>150</Price> 
        <Adult>1</Adult> 
        <child>0</child> 
      </room>
    </rooms>
    <rooms>
      <room>
        <roomname>Double</roomname> 
        <Price>200</Price> 
        <Adult>2</Adult> 
        <child>1</child> 
      </room>
    </rooms>   
  </hotel>
</HotelDetails>

to give:

Hotel :   
Single-100,
Double-200,
Total 300

Single-150,
Double-200,
Total 350

I try to sort with below code, but it comes like constant (distinct data). Anyone have an idea to sort above XML use something like below code?

<%@ Language="VBScript" CodePage="65001"%>  
<%  
Response.ContentType = "text/plain; charset=UTF-8"  

Dim doc   
Set doc = Server.CreateObject("Msxml2.DOMDocument.3.0") 
doc.async = False  

If doc.load(Server.MapPath("ee.xml")) Then   
  doc.setProperty "SelectionLanguage", "XPath"

  Dim xpath
  xpath = "HotelDetails/hotel/rooms[not(room/Adult= preceding-sibling::rooms/room/Adult)]/room/Adult"

  For Each Adult in doc.selectNodes(xpath) 
    Response.Write "Hotel" & VbCrLf
    Response.Write Adult.ChildNodes.Item(0).Text & VbCrLf  
  Next
Else   
  Response.Write doc.parseError.reason   
End If 
%>

How can I do this?

A: 

Would this be helpful http://www.developer.com/xml/article.php/1560361 , It shows how to use XSL transformation to output XML sorted in the form of HTML, But I think you can modify XSL output to be XML (<xsl:output>)

If these records coming from SQL Server, It is much easier to output them sorted already.. Are you trying to do caching??

If you trying to do caching , check my post: http://www.moretechtips.net/2008/11/object-oriented-data-caching-for.html

Mike More
A: 

Thanks for the repaly,

There is any possible way to sort the room list with out xsl?

Alex
Please use comments to comment on an answer. Don't post an own answer in place of a comment, this is not how this web site works. You should delete this answer.
Tomalak
+1  A: 

Another possibility is to use an ADODB Disconnected Recordset, and use the ADODB tools for sorting and extracting.

Good places to start reading up on this are:

boost