XML Editor
Sign up for a WebBoard account Sign Up Keyword Search Search More Options... Options
Chat Rooms Chat Help Help News News Log in to WebBoard Log in Not Logged in
Show tree view Topic
Topic Page 1 2 3 4 5 6 7 8 9 Go to previous topicPrev TopicGo to next topicNext Topic
Postnext
Srini VenkatSubject: output XML using XSLT
Author: Srini Venkat
Date: 19 Oct 2007 11:17 AM
Hi

I am developing the hotel accomodation search.During the hotel search, I will get multiple xml files(totally different structure but has got common elements) as a response from different sources. These files are stored on the same location. Now I would like to have a XSLT to combine these two xml files and output the results to a single xml file. And from this file the results need to be displayed. Here are my xml response files.

first.xml
---------

<?xml version="1.0" encoding="UTF-8"?>
<hotelList1>
<hotel>
<name>ABC</name>
<starRating>5 Star</starRating>
<roomType>Standard</roomType>
<status>Yes</status>
<boardBasis>Breakfast</boardBasis>
<currency>USD</currency>
<totalPrice>350</totalPrice>
</hotel>
<hotel>
<name>XYZ</name>
<starRating>3 Star</starRating>
<roomType>Standard</roomType>
<status>Yes</status>
<boardBasis>Breakfast</boardBasis>
<currency>USD</currency>
<totalPrice>171</totalPrice>
</hotel>
</hotelList1>

second.xml
---------
<?xml version="1.0" encoding="UTF-8"?>
<hotelList2>
<ServiceHotel>
<Currency code="USD">DOLLAR U.S.A.</Currency>
<HotelInfo>
<Code>12744</Code>
<Name>Venetian(BAR)</Name>
<Category>5 STARS</Category>
</HotelInfo>
<AvailableRoom>
<HotelRoom>
<Board>ROOM ONLY</Board>
<RoomType>DOUBLE DELUXE</RoomType>
<Status>Yes</Status>
<Price>
<Amount>1023.890</Amount>
</Price>
</HotelRoom>
</AvailableRoom>
</ServiceHotel>
<ServiceHotel>
<Currency code="USD">DOLLAR U.S.A.</Currency>
<HotelInfo>
<Code>12743</Code>
<Name>Tuscany Suites &amp; Casino(BAR)</Name>
<Category>3 STARS AND A HALF</Category>
</HotelInfo>
<AvailableRoom>
<HotelRoom>
<Board>ROOM ONLY</Board>
<RoomType>DOUBLE 2 DOUBLE BEDS</RoomType>
<Status>Yes</Status>
<Price>
<Amount>485.760</Amount>
</Price>
</HotelRoom>
</AvailableRoom>
</ServiceHotel>
</hotelList2>


Here is my XSLT file

combine.xsl
-----------

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" encoding="UTF-8"/>
<xsl:template match="/">
<Results>
<xsl:apply-templates select="document('first.xml')/hotelList1" />
<xsl:apply-templates select="document('second.xml')/hotelList2" />
</Results>
</xsl:template>
<xsl:template match="hotelList1">
<xsl:for-each select="hotel">
<Hotel>
<Name><xsl:value-of select="name" /></Name>
<StarRating><xsl:value-of select="starRating" /></StarRating>
<Price><xsl:value-of select="totalPrice" /></Price>
</Hotel>
</xsl:for-each>
</xsl:template>
<xsl:template match="hotelList2">
<xsl:for-each select="ServiceHotel">
<Hotel>
<Name><xsl:copy-of select="HotelInfo/Name" /></Name>
<StarRating><xsl:copy-of select="HotelInfo/Category" /></StarRating>
<Price><xsl:copy-of select="AvailableRoom/HotelRoom/Price/Amount" /></Price>
</Hotel>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>

The output xml I need is

<Results>
<Hotel>
<Name>.....</Name>
<StarRating>....</StarRating>
<Price>....</Price>
</Hotel>
<Hotel>
<Name>....</Name>
<StarRating>....</StarRating>
<Price>....</Price>
</Hotel>
.......
........
</Results>

When I tried the above the output is not displaying as an xml file. It simply displays the results in a text. I need the output as a xml file so that I will process it and display the results on the front end. When i have the ouput xml file I can provide the different sort option aswell from the results. (That is sort based on price / Hotel name /Star Rating....etc).

I am new to xml/xslt. I have tried by incuding this on my first.xml
<?xml-stylesheet type="text/xsl" href="combine.xsl"?>
Also I tried this from javascript

var xml = new ActiveXObject("Microsoft.XMLDOM")
xml.async = false
xml.load("first.xml")
var xsl = new ActiveXObject("Microsoft.XMLDOM")
xsl.async = false
xsl.load("combine.xsl")
document.write(xml.transformNode(xsl))

But i am getting the same result..that is results are diplayed with value in text without xml elements.

Could anyone suggest me how to generate the output xml file and how to execute the xsl/xml files to achive that. I am new to this.

Please help.

Thanks
Svan

Postnext
James DurningSubject: output XML using XSLT
Author: James Durning
Date: 19 Oct 2007 04:27 PM
IE will display the resulting XML as html, so it ignores all the elements and simply outputs the text.

Use an actual XSLT processor to get the result XML. (eg Stylus Studio)

Postnext
Jamil TaylorSubject: output XML using XSLT
Author: Jamil Taylor
Date: 20 Oct 2007 04:50 AM
Actually, IE has support for XSLT 1.0. You can use it to perform this transformation.

All you have to do is add the following line right below the declaration of the XML document you wish to transform:

<?xml-stylesheet type="text/xsl" href="combine.xsl"?>

Postnext
Jamil TaylorSubject: output XML using XSLT
Author: Jamil Taylor
Date: 20 Oct 2007 02:25 PM
Here's a couple of things that may help you out:

First, Microsoft has a small utility that will validate and show XML content via context menus in IE. You can grab it here: http://www.microsoft.com/downloads/details.aspx?FamilyId=D23C1D2C-1571-4D61-BDA8-ADF9F6849DF9&displaylang=en

Second, with a small modification to your javascript, you can save the transformed XML document using MS's DOM:

function transform() {
var xml = new ActiveXObject("Microsoft.XMLDOM");
xml.async = false;
xml.load("first.xml");
var xsl = new ActiveXObject("Microsoft.XMLDOM");
xsl.async = false;
xsl.load("combine.xsl");
var xml2 = new ActiveXObject("Microsoft.XMLDOM");
var fso = new ActiveXObject("Scripting.FileSystemObject");
var file = fso.CreateTextFile("output.xml", 1);
xml.transformNodeToObject(xsl, xml2);
file.write(xml2.xml);
file.close();
}

Postnext
Srini VenkatSubject: output XML using XSLT
Author: Srini Venkat
Date: 22 Oct 2007 09:53 AM
Thanks all for your help. Jamil, as you mentioned now i am able to write the output to a file. Thanks. My another question to james is how do we use the XSLT processors like styles studio for our xsl/xml operations. These two are going to reside on a specific location in a server and how to integrate these with style studio on the fly. I mean during the search operation in the front end.

Postnext
Alberto MassariSubject: output XML using XSLT
Author: Alberto Massari
Date: 25 Oct 2007 07:48 AM
Hi Srini,
Stylus Studio is not a server-side component that can be invoked "on the fly", it's a development environment. Depending on the server environment you have, you could be interested in adopting server-side components like DataDirect XQuery and/or XML Converters, or just use XSL processors like MSXSL/Saxon/XalanJ.
If you need more guidance, please describe your server application with more details.

Alberto

Postnext
Srini VenkatSubject: output XML using XSLT
Author: Srini Venkat
Date: 29 Oct 2007 11:58 AM
Hi Alberto

Thanks for your info. Basically I am devloping a search engine for checking availability for hotels/resorts and flights. Mostly this application involves sending data to various data providers and receive responses as an xml file. I am using xml/xslt for these purposes. Do you think I need some tools like style studio for the development.Will that reduce programming time? I have no idea on this.

Thanks
Srini

Posttop
Alberto MassariSubject: output XML using XSLT
Author: Alberto Massari
Date: 31 Oct 2007 01:50 PM
Hi Srini,
a development environment like Stylus Studio will greatly reduce your development time (compared to using Notepad to write the XML/XSLT and command line tools for testing them).

Alberto

 
Topic Page 1 2 3 4 5 6 7 8 9 Go to previous topicPrev TopicGo to next topicNext Topic
Download A Free Trial of Stylus Studio 6 XML Professional Edition Today! Powered by Stylus Studio, the world's leading XML IDE for XML, XSLT, XQuery, XML Schema, DTD, XPath, WSDL, XHTML, SQL/XML, and XML Mapping!  
go

Log In Options

Site Map | Privacy Policy | Terms of Use | Trademarks
Stylus Scoop XML Newsletter:
W3C Member
Stylus Studio® and DataDirect XQuery ™are from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2016 All Rights Reserved.