Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > XML > BOOK: XSLT Programmer's Reference, 2nd Edition
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
BOOK: XSLT Programmer's Reference, 2nd Edition
This is the forum to discuss the Wrox book XSLT: Programmer's Reference, 2nd Edition by Michael Kay; ISBN: 9780764543814
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: XSLT Programmer's Reference, 2nd Edition section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
 
 
Thread Tools Display Modes
  #1 (permalink)  
Old January 26th, 2010, 06:02 AM
Authorized User
 
Join Date: Jan 2010
Posts: 33
Thanks: 13
Thanked 0 Times in 0 Posts
Default XML transformation question

I have an assignment which is as follows,

<Hotel>
<hotelId>109277</hotelId>
<name>Park Central New York Hotel</name>
<address1>870 7th Ave</address1>
<address2/>
<address3/>
<city>New York</city>
<stateProvince>NY</stateProvince>
<country>US</country>
<postalCode>10019</postalCode>
<airportCode>NYC</airportCode>
<lowRate>299.0</lowRate>
<highRate>399.0</highRate>
<rateCurrencyCode>USD</rateCurrencyCode>
<latitude>40.76452</latitude>
<longitude>-73.98078</longitude>
<shortDescription>&amp;lt;b&amp;gt;Location.&amp;l t;/b&amp;gt;&amp;lt;br /&amp;gt; &amp;lt;UL&amp;gt;&amp;lt;LI&amp;gt;Park Central New York Hotel is located in New York, N.Y.</shortDescription>
<thumbNailUrl>/hotels/thumbs/OM_PARKC-exter-1-thumb.jpg</thumbNailUrl>
<supplierType>H</supplierType>
<location>CARNEGIE HALL - ACROSS THE ST.</location>
<propertyRating>3.5</propertyRating>
<propertyType>1</propertyType>
<marketingLevel>1</marketingLevel>
<hasMap>true</hasMap>
<hotelInDestination>false</hotelInDestination>
<referenceProximityDistance>-1.0</referenceProximityDistance>
<referenceProximityUnit/>
<HotelProperty>
<specialRate>N</specialRate>
<promoDescription/>
<promoType/>
<promoDetailText/>
<hrnQuoteKey>03A830122315114568</hrnQuoteKey>
<currentAllotment>-1</currentAllotment>
<propertyId>4164</propertyId>
<propertyAvailable>true</propertyAvailable>
<propertyRestricted>false</propertyRestricted>
<roomDescription>Superior 1 King - Non Smoking</roomDescription>
<roomTypeCode>476</roomTypeCode>
<rateCode>476</rateCode>
<RateInfo>
<displayCurrencyCode>USD</displayCurrencyCode>
<DisplayNightlyRates size="2">
<displayNightlyRate>399.0</displayNightlyRate>
<displayNightlyRate>299.0</displayNightlyRate>
</DisplayNightlyRates>
<displayRoomRate>825.41</displayRoomRate>
<chargeableRoomRateTotal>825.41</chargeableRoomRateTotal>
<chargeableRoomRateTaxesAndFees>127.41</chargeableRoomRateTaxesAndFees>
<nativeCurrencyCode>USD</nativeCurrencyCode>
<NativeNightlyRates size="2">
<nativeNightlyRate>399.0</nativeNightlyRate>
<nativeNightlyRate>299.0</nativeNightlyRate>
</NativeNightlyRates>
<nativeRoomRate>825.41</nativeRoomRate>
<rateFrequency>B</rateFrequency>
</RateInfo>
<PromoRateInfo>
<displayCurrencyCode>USD</displayCurrencyCode>
<DisplayNightlyRates size="2">
<displayNightlyRate>399.0</displayNightlyRate>
<displayNightlyRate>299.0</displayNightlyRate>
</DisplayNightlyRates>
<displayRoomRate>825.41</displayRoomRate>
<chargeableRoomRateTotal>825.41</chargeableRoomRateTotal>
<chargeableRoomRateTaxesAndFees>127.41</chargeableRoomRateTaxesAndFees>
<nativeCurrencyCode>USD</nativeCurrencyCode>
<NativeNightlyRates size="2">
<nativeNightlyRate>399.0</nativeNightlyRate>
<nativeNightlyRate>299.0</nativeNightlyRate>
</NativeNightlyRates>
<nativeRoomRate>825.41</nativeRoomRate>
<rateFrequency>B</rateFrequency>
</PromoRateInfo>
</HotelProperty>
</Hotel>


To form a ASP.NET dropdownlist I transformed the XML from elements to attributes and reduced it to just the four elements that are relevant to the assignment and saves it as another XML file. The dropdownlist includes hotelId as SelectedValue and name as SelectedItem. When an item is selected it has already retuned the selectedValue. With that said, my challenges are to assure that the new XML file was transformed correctly so it can be input into a .NET dataset where query can be run against it to return data based on hotelId from the dropdown SelectedValue content. Can you help me with this transformation to extract four elements out of a xml file that has multiple elements including one element RateInfo which has some child elements and some attributes. The template also need to have a key, hotelId. The RateInfo can be transformed to output with attributes separated by a comma.

Thanks,
  #2 (permalink)  
Old January 26th, 2010, 06:42 AM
samjudson's Avatar
Friend of Wrox
Points: 8,687, Level: 40
Points: 8,687, Level: 40 Points: 8,687, Level: 40 Points: 8,687, Level: 40
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2007
Location: Newcastle, , United Kingdom.
Posts: 2,133
Thanks: 1
Thanked 189 Times in 188 Posts
Default

I don't think you'll find you'll get any different answers here than you will on the dedicated XSLT forum.

The main problem with what you are asking is that you do no tell us what you want you output XML to look like. With an example input and an example output we can help you write an XSLT stylesheet which will perform the transformation from one to the other. Without one or the other we would be left making huge guesses, which we really have better things to do.

Also you talk about multiple hotels, but your XML above only contains 1 hotel, therefore there is probably some XML you are not showing us.

And you keep using various words that we're not sure mean what we usually take them to mean. For example in XSLT the word 'template' has a very specific meaning - its a section of an XSLT transformation that handles a particular function or element. Likewise when you refer to 'attribute' are you talking about an XML attribute, or do you really mean element?
__________________
/- Sam Judson : Wrox Technical Editor -/

Think before you post: What have you tried?
The Following User Says Thank You to samjudson For This Useful Post:
jtnchang (January 26th, 2010)
  #3 (permalink)  
Old January 26th, 2010, 06:06 PM
Authorized User
 
Join Date: Jan 2010
Posts: 33
Thanks: 13
Thanked 0 Times in 0 Posts
Default

Hi,

My apologies for not providing a output due to my lack of XSL knowledge. Here is the complete xml file followed by the output. Input test xml file has five hotels but the requirment demands the solution to be scalable. Feel free to ask for further clarification if need be. Thanks.


<HotelAvailabilityListResults size="5">
<Hotel>
<hotelId>109277</hotelId>
<name>Park Central New York Hotel</name>
<address1>870 7th Ave</address1>
<address2/>
<address3/>
<city>New York</city>
<stateProvince>NY</stateProvince>
<country>US</country>
<postalCode>10019</postalCode>
<airportCode>NYC</airportCode>
<lowRate>299.0</lowRate>
<highRate>399.0</highRate>
<rateCurrencyCode>USD</rateCurrencyCode>
<latitude>40.76452</latitude>
<longitude>-73.98078</longitude>
<shortDescription>&amp;lt;b&amp;gt;Location.&amp;l t;/b&amp;gt;&amp;lt;br /&amp;gt; &amp;lt;UL&amp;gt;&amp;lt;LI&amp;gt;Park Central New York Hotel is located in New York, N.Y.</shortDescription>
<thumbNailUrl>/hotels/thumbs/OM_PARKC-exter-1-thumb.jpg</thumbNailUrl>
<supplierType>H</supplierType>
<location>CARNEGIE HALL - ACROSS THE ST.</location>
<propertyRating>3.5</propertyRating>
<propertyType>1</propertyType>
<marketingLevel>1</marketingLevel>
<hasMap>true</hasMap>
<hotelInDestination>false</hotelInDestination>
<referenceProximityDistance>-1.0</referenceProximityDistance>
<referenceProximityUnit/>
<HotelProperty>
<specialRate>N</specialRate>
<promoDescription/>
<promoType/>
<promoDetailText/>
<hrnQuoteKey>03A830122315114568</hrnQuoteKey>
<currentAllotment>-1</currentAllotment>
<propertyId>4164</propertyId>
<propertyAvailable>true</propertyAvailable>
<propertyRestricted>false</propertyRestricted>
<roomDescription>Superior 1 King - Non Smoking</roomDescription>
<roomTypeCode>476</roomTypeCode>
<rateCode>476</rateCode>
<RateInfo>
<displayCurrencyCode>USD</displayCurrencyCode>
<DisplayNightlyRates size="2">
<displayNightlyRate>399.0</displayNightlyRate>
<displayNightlyRate>299.0</displayNightlyRate>
</DisplayNightlyRates>
<displayRoomRate>825.41</displayRoomRate>
<chargeableRoomRateTotal>825.41</chargeableRoomRateTotal>
<chargeableRoomRateTaxesAndFees>127.41</chargeableRoomRateTaxesAndFees>
<nativeCurrencyCode>USD</nativeCurrencyCode>
<NativeNightlyRates size="2">
<nativeNightlyRate>399.0</nativeNightlyRate>
<nativeNightlyRate>299.0</nativeNightlyRate>
</NativeNightlyRates>
<nativeRoomRate>825.41</nativeRoomRate>
<rateFrequency>B</rateFrequency>
</RateInfo>
<PromoRateInfo>
<displayCurrencyCode>USD</displayCurrencyCode>
<DisplayNightlyRates size="2">
<displayNightlyRate>399.0</displayNightlyRate>
<displayNightlyRate>299.0</displayNightlyRate>
</DisplayNightlyRates>
<displayRoomRate>825.41</displayRoomRate>
<chargeableRoomRateTotal>825.41</chargeableRoomRateTotal>
<chargeableRoomRateTaxesAndFees>127.41</chargeableRoomRateTaxesAndFees>
<nativeCurrencyCode>USD</nativeCurrencyCode>
<NativeNightlyRates size="2">
<nativeNightlyRate>399.0</nativeNightlyRate>
<nativeNightlyRate>299.0</nativeNightlyRate>
</NativeNightlyRates>
<nativeRoomRate>825.41</nativeRoomRate>
<rateFrequency>B</rateFrequency>
</PromoRateInfo>
</HotelProperty>
</Hotel>
<Hotel>
<hotelId>112922</hotelId>
<name>Hilton New York</name>
<address1>1335 Avenue Of The Americas</address1>
<address2/>
<address3/>
<city>New York</city>
<stateProvince>NY</stateProvince>
<country>US</country>
<postalCode>10019</postalCode>
<airportCode>NYC</airportCode>
<lowRate>329.0</lowRate>
<highRate>329.0</highRate>
<rateCurrencyCode>USD</rateCurrencyCode>
<latitude>40.76225</latitude>
<longitude>-73.97874</longitude>
<shortDescription>&amp;lt;b&amp;gt;Location.&amp;l t;/b&amp;gt; The Hilton New York is located in Midtown New York, N.Y., across the street from the Museum of Modern Art and the American Folk Art Museum.</shortDescription>
<thumbNailUrl>/hotels/thumbs/NYC_HILT-exter-1-thumb.jpg</thumbNailUrl>
<supplierType>H</supplierType>
<location>MOMA - ACROSS THE STREET</location>
<propertyRating>3.5</propertyRating>
<propertyType>1</propertyType>
<marketingLevel>2</marketingLevel>
<hasMap>true</hasMap>
<hotelInDestination>false</hotelInDestination>
<referenceProximityDistance>-1.0</referenceProximityDistance>
<referenceProximityUnit/>
<HotelProperty>
<specialRate>P</specialRate>
<promoDescription/>
<promoType/>
<promoDetailText/>
<hrnQuoteKey>03A830122315114568</hrnQuoteKey>
<currentAllotment>-1</currentAllotment>
<propertyId>19768</propertyId>
<propertyAvailable>true</propertyAvailable>
<propertyRestricted>false</propertyRestricted>
<roomDescription>Standard Queen-Non Refundable</roomDescription>
<roomTypeCode>45117</roomTypeCode>
<rateCode>172199</rateCode>
<RateInfo>
<displayCurrencyCode>USD</displayCurrencyCode>
<DisplayNightlyRates size="2">
<displayNightlyRate>329.0</displayNightlyRate>
<displayNightlyRate>329.0</displayNightlyRate>
</DisplayNightlyRates>
<displayRoomRate>781.42</displayRoomRate>
<chargeableRoomRateTotal>781.42</chargeableRoomRateTotal>
<chargeableRoomRateTaxesAndFees>123.42</chargeableRoomRateTaxesAndFees>
<nativeCurrencyCode>USD</nativeCurrencyCode>
<NativeNightlyRates size="2">
<nativeNightlyRate>329.0</nativeNightlyRate>
<nativeNightlyRate>329.0</nativeNightlyRate>
</NativeNightlyRates>
<nativeRoomRate>781.42</nativeRoomRate>
<rateFrequency>B</rateFrequency>
</RateInfo>
</HotelProperty>
</Hotel>
<Hotel>
<hotelId>140893</hotelId>
<name>The Belvedere Hotel</name>
<address1>319 W 48th St</address1>
<address2/>
<address3/>
<city>New York</city>
<stateProvince>NY</stateProvince>
<country>US</country>
<postalCode>10036</postalCode>
<airportCode>NYC</airportCode>
<lowRate>293.33</lowRate>
<highRate>398.67</highRate>
<rateCurrencyCode>USD</rateCurrencyCode>
<latitude>40.76129</latitude>
<longitude>-73.98751</longitude>
<shortDescription>&amp;lt;b&amp;gt;Location.&amp;l t;/b&amp;gt;&amp;lt;br&amp;gt; &amp;lt;UL&amp;gt;&amp;lt;LI&amp;gt;The Belvedere Hotel is located in New York, N.Y.</shortDescription>
<thumbNailUrl>/hotels/thumbs/NYC_BELV-exter-1-thumb.jpg</thumbNailUrl>
<supplierType>H</supplierType>
<location>ROCKEFELLER CENTER 3 BLOCKS</location>
<propertyRating>3.0</propertyRating>
<propertyType>1</propertyType>
<marketingLevel>1</marketingLevel>
<hasMap>true</hasMap>
<hotelInDestination>false</hotelInDestination>
<referenceProximityDistance>-1.0</referenceProximityDistance>
<referenceProximityUnit/>
<HotelProperty>
<specialRate>N</specialRate>
<promoDescription/>
<promoType/>
<promoDetailText/>
<hrnQuoteKey>03A830122315114568</hrnQuoteKey>
<currentAllotment>4</currentAllotment>
<propertyId>104193</propertyId>
<propertyAvailable>true</propertyAvailable>
<propertyRestricted>false</propertyRestricted>
<roomDescription>Deluxe King</roomDescription>
<roomTypeCode>97306</roomTypeCode>
<rateCode>221517</rateCode>
<RateInfo>
<displayCurrencyCode>USD</displayCurrencyCode>
<DisplayNightlyRates size="2">
<displayNightlyRate>398.67</displayNightlyRate>
<displayNightlyRate>293.33</displayNightlyRate>
</DisplayNightlyRates>
<displayRoomRate>818.33</displayRoomRate>
<chargeableRoomRateTotal>818.33</chargeableRoomRateTotal>
<chargeableRoomRateTaxesAndFees>126.33</chargeableRoomRateTaxesAndFees>
<nativeCurrencyCode>USD</nativeCurrencyCode>
<NativeNightlyRates size="2">
<nativeNightlyRate>398.67</nativeNightlyRate>
<nativeNightlyRate>293.33</nativeNightlyRate>
</NativeNightlyRates>
<nativeRoomRate>818.33</nativeRoomRate>
<rateFrequency>B</rateFrequency>
</RateInfo>
</HotelProperty>
</Hotel>
<Hotel>
<hotelId>112522</hotelId>
<name>Wellington Hotel</name>
<address1>871 7th Ave</address1>
<address2/>
<address3/>
<city>New York</city>
<stateProvince>NY</stateProvince>
<country>US</country>
<postalCode>10019</postalCode>
<airportCode>NYC</airportCode>
<lowRate>239.2</lowRate>
<highRate>399.0</highRate>
<rateCurrencyCode>USD</rateCurrencyCode>
<latitude>40.76446</latitude>
<longitude>-73.98082</longitude>
<shortDescription>&amp;lt;b&amp;gt;Location.&amp;l t;/b&amp;gt;&amp;lt;br&amp;gt; &amp;lt;UL&amp;gt;&amp;lt;LI&amp;gt;The Wellington Hotel is located in New York, N.Y.</shortDescription>
<thumbNailUrl>/hotels/thumbs/NC_WELLI-exter-1-thumb.jpg</thumbNailUrl>
<supplierType>H</supplierType>
<location>THEATER DISTRICT MIDTOWN</location>
<propertyRating>3.0</propertyRating>
<propertyType>1</propertyType>
<marketingLevel>1</marketingLevel>
<hasMap>true</hasMap>
<hotelInDestination>false</hotelInDestination>
<referenceProximityDistance>-1.0</referenceProximityDistance>
<referenceProximityUnit/>
<HotelProperty>
<specialRate>N</specialRate>
<promoDescription>Best Price</promoDescription>
<promoType/>
<promoDetailText/>
<hrnQuoteKey>03A830122315114568</hrnQuoteKey>
<currentAllotment>-1</currentAllotment>
<propertyId>25888</propertyId>
<propertyAvailable>true</propertyAvailable>
<propertyRestricted>false</propertyRestricted>
<roomDescription>Standard room with double bed</roomDescription>
<roomTypeCode>5662</roomTypeCode>
<rateCode>5662</rateCode>
<RateInfo>
<displayCurrencyCode>USD</displayCurrencyCode>
<DisplayNightlyRates size="2">
<displayNightlyRate>399.0</displayNightlyRate>
<displayNightlyRate>299.0</displayNightlyRate>
</DisplayNightlyRates>
<displayRoomRate>799.7</displayRoomRate>
<chargeableRoomRateTotal>799.7</chargeableRoomRateTotal>
<chargeableRoomRateTaxesAndFees>101.7</chargeableRoomRateTaxesAndFees>
<nativeCurrencyCode>USD</nativeCurrencyCode>
<NativeNightlyRates size="2">
<nativeNightlyRate>399.0</nativeNightlyRate>
<nativeNightlyRate>299.0</nativeNightlyRate>
</NativeNightlyRates>
<nativeRoomRate>799.7</nativeRoomRate>
<rateFrequency>B</rateFrequency>
</RateInfo>
<PromoRateInfo>
<displayCurrencyCode>USD</displayCurrencyCode>
<DisplayNightlyRates size="2">
<displayNightlyRate>319.2</displayNightlyRate>
<displayNightlyRate>239.2</displayNightlyRate>
</DisplayNightlyRates>
<displayRoomRate>660.1</displayRoomRate>
<chargeableRoomRateTotal>660.1</chargeableRoomRateTotal>
<chargeableRoomRateTaxesAndFees>101.7</chargeableRoomRateTaxesAndFees>
<nativeCurrencyCode>USD</nativeCurrencyCode>
<NativeNightlyRates size="2">
<nativeNightlyRate>319.2</nativeNightlyRate>
<nativeNightlyRate>239.2</nativeNightlyRate>
</NativeNightlyRates>
<nativeRoomRate>660.1</nativeRoomRate>
<rateFrequency>B</rateFrequency>
</PromoRateInfo>
</HotelProperty>
</Hotel>
<Hotel>
<hotelId>111484</hotelId>
<name>Salisbury Hotel</name>
<address1>123 W 57th St</address1>
<address2/>
<address3/>
<city>New York</city>
<stateProvince>NY</stateProvince>
<country>US</country>
<postalCode>10019</postalCode>
<airportCode>NYC</airportCode>
<lowRate>223.2</lowRate>
<highRate>299.0</highRate>
<rateCurrencyCode>USD</rateCurrencyCode>
<latitude>40.76462</latitude>
<longitude>-73.97782</longitude>
<shortDescription>&amp;lt;b&amp;gt;Location.&amp;l t;/b&amp;gt;&amp;lt;br&amp;gt; &amp;lt;UL&amp;gt;&amp;lt;LI&amp;gt;The Salisbury Hotel is located in New York, N.Y.</shortDescription>
<thumbNailUrl>/hotels/thumbs/NYC_SALI-exter-1-thumb.jpg</thumbNailUrl>
<supplierType>H</supplierType>
<location>CARNEGIE HALL</location>
<propertyRating>2.5</propertyRating>
<propertyType>1</propertyType>
<marketingLevel>1</marketingLevel>
<hasMap>true</hasMap>
<hotelInDestination>false</hotelInDestination>
<referenceProximityDistance>-1.0</referenceProximityDistance>
<referenceProximityUnit/>
<HotelProperty>
<specialRate>N</specialRate>
<promoDescription>Stay 2 nights and save 20% off your stay!</promoDescription>
<promoType/>
<promoDetailText/>
<hrnQuoteKey>03A830122315114568</hrnQuoteKey>
<currentAllotment>-1</currentAllotment>
<propertyId>25906</propertyId>
<propertyAvailable>true</propertyAvailable>
<propertyRestricted>false</propertyRestricted>
<roomDescription>Standard Room</roomDescription>
<roomTypeCode>2612</roomTypeCode>
<rateCode>2612</rateCode>
<RateInfo>
<displayCurrencyCode>USD</displayCurrencyCode>
<DisplayNightlyRates size="2">
<displayNightlyRate>299.0</displayNightlyRate>
<displayNightlyRate>279.0</displayNightlyRate>
</DisplayNightlyRates>
<displayRoomRate>666.05</displayRoomRate>
<chargeableRoomRateTotal>666.05</chargeableRoomRateTotal>
<chargeableRoomRateTaxesAndFees>88.05</chargeableRoomRateTaxesAndFees>
<nativeCurrencyCode>USD</nativeCurrencyCode>
<NativeNightlyRates size="2">
<nativeNightlyRate>299.0</nativeNightlyRate>
<nativeNightlyRate>279.0</nativeNightlyRate>
</NativeNightlyRates>
<nativeRoomRate>666.05</nativeRoomRate>
<rateFrequency>B</rateFrequency>
</RateInfo>
<PromoRateInfo>
<displayCurrencyCode>USD</displayCurrencyCode>
<DisplayNightlyRates size="2">
<displayNightlyRate>239.2</displayNightlyRate>
<displayNightlyRate>223.2</displayNightlyRate>
</DisplayNightlyRates>
<displayRoomRate>550.45</displayRoomRate>
<chargeableRoomRateTotal>550.45</chargeableRoomRateTotal>
<chargeableRoomRateTaxesAndFees>88.05</chargeableRoomRateTaxesAndFees>
<nativeCurrencyCode>USD</nativeCurrencyCode>
<NativeNightlyRates size="2">
<nativeNightlyRate>239.2</nativeNightlyRate>
<nativeNightlyRate>223.2</nativeNightlyRate>
</NativeNightlyRates>
<nativeRoomRate>550.45</nativeRoomRate>
<rateFrequency>B</rateFrequency>
</PromoRateInfo>
</HotelProperty>
</Hotel>
<moreResultsAvailable>true</moreResultsAvailable>
<cacheKey>ab876b3:12458612a38:12ee</cacheKey>
<cacheLocation>10.186.168.48:7301</cacheLocation>
<numberOfRoomsRequested>1</numberOfRoomsRequested>
</HotelAvailabilityListResults>

Take the first element as an example:

<score id="1">
<film>A Little Princess</film>
<composer>Patrick Doyle</composer>
<year>1995</year>
<grade>100</grade>
</score>
With these changes applied, the new element looks like this:

<score id="1" film="A Little Princess" composer="Patrick
Doyle" releasedate="1995"/>

-----------output-------------

<HotelAvailabilityListResults size="5">
<Hotel>
<hotelId>109277</hotelId>
<name>Park Central New York Hotel</name>
<address1>870 7th Ave</address1>
<shortDescription>&amp;lt;b&amp;gt;Location.&amp;l t;/b&amp;gt;&amp;lt;br&amp;gt; &amp;lt;UL&amp;gt;&amp;lt;LI&amp;gt;The Salisbury Hotel is located in New York, N.Y.</shortDescription>
<RateInfo>
<displayCurrencyCode>USD</displayCurrencyCode>
<DisplayNightlyRates size="2">
<displayNightlyRate>299.0</displayNightlyRate>
<displayNightlyRate>279.0</displayNightlyRate>
</DisplayNightlyRates>
<displayRoomRate>666.05</displayRoomRate>
<chargeableRoomRateTotal>666.05</chargeableRoomRateTotal>
<chargeableRoomRateTaxesAndFees>88.05</chargeableRoomRateTaxesAndFees>
<nativeCurrencyCode>USD</nativeCurrencyCode>
<NativeNightlyRates size="2">
<nativeNightlyRate>299.0</nativeNightlyRate>
<nativeNightlyRate>279.0</nativeNightlyRate>
</NativeNightlyRates>
<nativeRoomRate>666.05</nativeRoomRate>
<rateFrequency>B</rateFrequency>
</RateInfo>
</Hotel>
<Hotel>
<hotelId>112922</hotelId>
<name>Hilton New York</name>
<address1>1335 Avenue Of The Americas</address1>
<shortDescription>&amp;lt;b&amp;gt;Location.&amp;l t;/b&amp;gt; The Hilton New York is located in Midtown New York, N.Y., across the street from the Museum of Modern Art and the American Folk Art Museum.</shortDescription>
<RateInfo>
<displayCurrencyCode>USD</displayCurrencyCode>
<DisplayNightlyRates size="2">
<displayNightlyRate>329.0</displayNightlyRate>
<displayNightlyRate>329.0</displayNightlyRate>
</DisplayNightlyRates>
<displayRoomRate>781.42</displayRoomRate>
<chargeableRoomRateTotal>781.42</chargeableRoomRateTotal>
<chargeableRoomRateTaxesAndFees>123.42</chargeableRoomRateTaxesAndFees>
<nativeCurrencyCode>USD</nativeCurrencyCode>
<NativeNightlyRates size="2">
<nativeNightlyRate>329.0</nativeNightlyRate>
<nativeNightlyRate>329.0</nativeNightlyRate>
</NativeNightlyRates>
<nativeRoomRate>781.42</nativeRoomRate>
<rateFrequency>B</rateFrequency>
</RateInfo>
</Hotel>
<Hotel>
<hotelId>140893</hotelId>
<name>The Belvedere Hotel</name>
<address1>319 W 48th St</address1>
<shortDescription>&amp;lt;b&amp;gt;Location.&amp;l t;/b&amp;gt;&amp;lt;br&amp;gt; &amp;lt;UL&amp;gt;&amp;lt;LI&amp;gt;The Belvedere Hotel is located in New York, N.Y.</shortDescription>
<RateInfo>
<displayCurrencyCode>USD</displayCurrencyCode>
<DisplayNightlyRates size="2">
<displayNightlyRate>398.67</displayNightlyRate>
<displayNightlyRate>293.33</displayNightlyRate>
</DisplayNightlyRates>
<displayRoomRate>818.33</displayRoomRate>
<chargeableRoomRateTotal>818.33</chargeableRoomRateTotal>
<chargeableRoomRateTaxesAndFees>126.33</chargeableRoomRateTaxesAndFees>
<nativeCurrencyCode>USD</nativeCurrencyCode>
<NativeNightlyRates size="2">
<nativeNightlyRate>398.67</nativeNightlyRate>
<nativeNightlyRate>293.33</nativeNightlyRate>
</NativeNightlyRates>
<nativeRoomRate>818.33</nativeRoomRate>
<rateFrequency>B</rateFrequency>
</RateInfo>
</Hotel>
<Hotel>
<hotelId>112522</hotelId>
<name>Wellington Hotel</name>
<address1>871 7th Ave</address1>
<shortDescription>&amp;lt;b&amp;gt;Location.&amp;l t;/b&amp;gt;&amp;lt;br&amp;gt; &amp;lt;UL&amp;gt;&amp;lt;LI&amp;gt;The Wellington Hotel is located in New York, N.Y.</shortDescription>
<RateInfo>
<displayCurrencyCode>USD</displayCurrencyCode>
<DisplayNightlyRates size="2">
<displayNightlyRate>399.0</displayNightlyRate>
<displayNightlyRate>299.0</displayNightlyRate>
</DisplayNightlyRates>
<displayRoomRate>799.7</displayRoomRate>
<chargeableRoomRateTotal>799.7</chargeableRoomRateTotal>
<chargeableRoomRateTaxesAndFees>101.7</chargeableRoomRateTaxesAndFees>
<nativeCurrencyCode>USD</nativeCurrencyCode>
<NativeNightlyRates size="2">
<nativeNightlyRate>399.0</nativeNightlyRate>
<nativeNightlyRate>299.0</nativeNightlyRate>
</NativeNightlyRates>
<nativeRoomRate>799.7</nativeRoomRate>
<rateFrequency>B</rateFrequency>
</RateInfo>
</Hotel>
<Hotel>
<hotelId>111484</hotelId>
<name>Salisbury Hotel</name>
<address1>123 W 57th St</address1>
<shortDescription>&amp;lt;b&amp;gt;Location.&amp;l t;/b&amp;gt;&amp;lt;br&amp;gt; &amp;lt;UL&amp;gt;&amp;lt;LI&amp;gt;The Salisbury Hotel is located in New York, N.Y.</shortDescription>
<RateInfo>
<displayCurrencyCode>USD</displayCurrencyCode>
<DisplayNightlyRates size="2">
<displayNightlyRate>299.0</displayNightlyRate>
<displayNightlyRate>279.0</displayNightlyRate>
</DisplayNightlyRates>
<displayRoomRate>666.05</displayRoomRate>
<chargeableRoomRateTotal>666.05</chargeableRoomRateTotal>
<chargeableRoomRateTaxesAndFees>88.05</chargeableRoomRateTaxesAndFees>
<nativeCurrencyCode>USD</nativeCurrencyCode>
<NativeNightlyRates size="2">
<nativeNightlyRate>299.0</nativeNightlyRate>
<nativeNightlyRate>279.0</nativeNightlyRate>
</NativeNightlyRates>
<nativeRoomRate>666.05</nativeRoomRate>
<rateFrequency>B</rateFrequency>
</RateInfo>
</Hotel>
</HotelAvailabilityListResults>
  #4 (permalink)  
Old January 26th, 2010, 06:41 PM
mhkay's Avatar
Wrox Author
Points: 18,274, Level: 58
Points: 18,274, Level: 58 Points: 18,274, Level: 58 Points: 18,274, Level: 58
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,932
Thanks: 0
Thanked 282 Times in 277 Posts
Default

You really aren't making life easy for people who want to help you. Switching to a new thread on a different forum is like saying the same think louder when people say they don't understand you.

Producing your example output is easy. But I can't see how it relates to your description of the problem. The output doesn't include any attributes, let alone attributes separated by a comma, and being XML rather than HTML, I can't see where the drop-down list comes into it.

You essentially want two template rules, one for elements that need to be copied:

Code:
<xsl:template match="XXX">
  <xsl:copy><xsl:apply-templates/></xsl:copy>
</xsl:template>
and another for elements that need to be deleted:

Code:
<xsl:template match="YYY"/>
Since most of the elements are to be deleted, I would make the second rule the default one (match="*") and in the first rule, list the elements you want to retain: match="Hotel | hotelId | name | shortDescription | RateInfo | RateInfo/*"
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference
The Following User Says Thank You to mhkay For This Useful Post:
jtnchang (January 26th, 2010)
  #5 (permalink)  
Old January 26th, 2010, 09:47 PM
Authorized User
 
Join Date: Jan 2010
Posts: 33
Thanks: 13
Thanked 0 Times in 0 Posts
Default

My apologies if switching thread caused any inconvenience. I switched out of dyer desperation. As far as the transformation, Michael is correct in stating that I failed to provide the output in the attribute format as I mentioned previously. So I modified it but I did not put those comma delimeters inside the RateInfo attribute for I was not sure whether literal ","'s are acceptable. Nor did I do any format change with Displaynightlyrate and Nativenightlyrate. I put other attributes in that are address related thinking that the requirement might mean to include. So here it is the attribute format output the best way I can depict it.

<HotelAvailabilityListResults size="5">
<Hotel
hotelId: 109277
name: Park Central New York Hotel
address1: 870 7th Ave
address2/:
address3/:
city: New York
stateProvince: NY
country: US
postalCode: 10019
shortDescription: &amp;lt;b&amp;gt;Location.&amp;lt;/b&amp;gt;&amp;lt;br /&amp;gt; &amp;lt;UL&amp;gt;&amp;lt;LI&amp;gt;Park Central New York Hotel is located in New York, N.Y.
HotelProperty:
RateInfo:
displayCurrencyCode: USD
<DisplayNightlyRates size="2">
<displayNightlyRate: 399.0/displayNightlyRate>
<displayNightlyRate: 299.0/displayNightlyRate>
</DisplayNightlyRates>
displayRoomRate: 825.41
chargeableRoomRateTotal: 825.41
chargeableRoomRateTaxesAndFees: 127.41
nativeCurrencyCode: USD
<NativeNightlyRates size="2">
<nativeNightlyRate: 399.0/nativeNightlyRate>
<nativeNightlyRate: 299.0/nativeNightlyRate>
</NativeNightlyRates
nativeRoomRate: 825.41
rateFrequency: B >
<Hotel:
hotelId: 112922
name: Hilton New York
address1: 1335 Avenue Of The Americas
address2/:
address3/:
city: New York
stateProvince: NY
country: US
postalCode: 10019
shortDescription: &amp;lt;b&amp;gt;Location.&amp;lt;/b&amp;gt; The Hilton New York is located in Midtown New York, N.Y., across the street from the Museum of Modern Art and the American Folk Art Museum.
HotelProperty:
RateInfo:
displayCurrencyCode: USD
<DisplayNightlyRates size="2">
<displayNightlyRate: 329.0/displayNightlyRate>
<displayNightlyRate: 329.0/displayNightlyRate>
</DisplayNightlyRates>
displayRoomRate: 781.42
chargeableRoomRateTotal: 781.42
chargeableRoomRateTaxesAndFees: 123.42
nativeCurrencyCode: USD
<NativeNightlyRates size="2">
<nativeNightlyRate: 329.0/nativeNightlyRate>
<nativeNightlyRate: 329.0/nativeNightlyRate>
</NativeNightlyRates>
nativeRoomRate: 781.42
rateFrequency: B >
<Hotel:
hotelId: 140893
name: The Belvedere Hotel
address1: 319 W 48th St
address2/:
address3/:
city: New York
stateProvince: NY
country: US
postalCode: 10036
shortDescription: &amp;lt;b&amp;gt;Location.&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt; &amp;lt;UL&amp;gt;&amp;lt;LI&amp;gt;The Belvedere Hotel is located in New York, N.Y.
HotelProperty:
RateInfo:
displayCurrencyCode: USD
<DisplayNightlyRates size="2">
<displayNightlyRate: 398.67/displayNightlyRate>
<displayNightlyRate: 293.33/displayNightlyRate>
</DisplayNightlyRates>
displayRoomRate: 818.33
chargeableRoomRateTotal: 818.33
chargeableRoomRateTaxesAndFees: 126.33
nativeCurrencyCode: USD
<NativeNightlyRates size="2">
<nativeNightlyRate: 398.67/nativeNightlyRate>
<nativeNightlyRate: 293.33/nativeNightlyRate>
</NativeNightlyRates>
nativeRoomRate: 818.33
rateFrequency: B >
<Hotel:
hotelId: 112522
name: Wellington Hotel
address1: 871 7th Ave
address2/:
address3/:
city: New York
stateProvince: NY
country: US
postalCode: 10019
shortDescription: &amp;lt;b&amp;gt;Location.&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt; &amp;lt;UL&amp;gt;&amp;lt;LI&amp;gt;The Wellington Hotel is located in New York, N.Y.
HotelProperty:
RateInfo:
displayCurrencyCode: USD
<DisplayNightlyRates size="2">
<displayNightlyRate: 399.0/displayNightlyRate>
<displayNightlyRate: 299.0/displayNightlyRate>
</DisplayNightlyRates>
displayRoomRate: 799.7
chargeableRoomRateTotal: 799.7
chargeableRoomRateTaxesAndFees: 101.7
nativeCurrencyCode: USD
<NativeNightlyRates size="2">
<nativeNightlyRate: 399.0/nativeNightlyRate>
<nativeNightlyRate: 299.0/nativeNightlyRate>
</NativeNightlyRates>
nativeRoomRate: 799.7
rateFrequency: B >

<Hotel:
hotelId: 111484
name: Salisbury Hotel
address1: 123 W 57th St
address2/:
address3/:
city: New York/city:
stateProvince: NY/stateProvince:
country: US/country:
postalCode: 10019/postalCode:
shortDescription: &amp;lt;b&amp;gt;Location.&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt; &amp;lt;UL&amp;gt;&amp;lt;LI&amp;gt;The Salisbury Hotel is located in New York, N.Y.
HotelProperty:
RateInfo:
displayCurrencyCode: USD
<DisplayNightlyRates size="2">
<displayNightlyRate: 299.0/displayNightlyRate>
<displayNightlyRate: 279.0/displayNightlyRate>
</DisplayNightlyRates>
displayRoomRate: 666.05
chargeableRoomRateTotal: 666.05
chargeableRoomRateTaxesAndFees: 88.05
nativeCurrencyCode: USD
<NativeNightlyRates size="2":
<nativeNightlyRate: 299.0/nativeNightlyRate>
<nativeNightlyRate: 279.0/nativeNightlyRate>
</NativeNightlyRates>
nativeRoomRate: 666.05
rateFrequency: B >
<moreResultsAvailable: true/moreResultsAvailable>
<cacheKey: ab876b3:12458612a38:12ee/cacheKey>
<cacheLocation: 10.186.168.48:7301/cacheLocation>
<numberOfRoomsRequested: 1/numberOfRoomsRequested>
</HotelAvailabilityListResults>
  #6 (permalink)  
Old January 27th, 2010, 04:48 AM
mhkay's Avatar
Wrox Author
Points: 18,274, Level: 58
Points: 18,274, Level: 58 Points: 18,274, Level: 58 Points: 18,274, Level: 58
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,932
Thanks: 0
Thanked 282 Times in 277 Posts
Default

<Hotel:
hotelId: 111484

Why would you want to produce output in a format that has many similarities with XML, but is not XML? What do you intend to do with this output? What can you do with it that you couldn't do with the original XML?
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference
The Following User Says Thank You to mhkay For This Useful Post:
jtnchang (January 27th, 2010)
  #7 (permalink)  
Old January 27th, 2010, 02:58 PM
Authorized User
 
Join Date: Jan 2010
Posts: 33
Thanks: 13
Thanked 0 Times in 0 Posts
Default

Michael,

All I need to do is two things:
1. to populate the dropdownlist so user can select the hotel from the list.

2. to populate the key info of the hotel selected into a Label control so it will be displayed on the page upon selectionchanged event.

I first used attributes because I saw a sample code that use XML attributes to populate a dropdown so I thought I had to first convert elements to attributes. And now I already identified that .NET linq has access to XML.attribute(attributename) so I can accomplish populating Label control using attributes. So my understanding now is that I just need one XSL transformation to convert elements to attributes and that should take care of both parts 1 and 2. As I mentioned that I had not much XML/XSLT experience so I am not sure if there is one way to do what I need to do with the original XML. And it makes sense for me to convert to attributes for it sounds like a resolution. I am sure there may be other solutions but I just need a solution ASAP.

Thanks,
  #8 (permalink)  
Old January 27th, 2010, 04:21 PM
mhkay's Avatar
Wrox Author
Points: 18,274, Level: 58
Points: 18,274, Level: 58 Points: 18,274, Level: 58 Points: 18,274, Level: 58
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,932
Thanks: 0
Thanked 282 Times in 277 Posts
Default

I think you need to do a lot more reading before you do any more coding. You haven't grasped the key concepts about the architecture of the application you are building. You don't need to generate attributes, and you don't even seem to know what attributes are.

Your difficulty is that you haven't got it clear in your head what output you want your stylesheet to produce. As Dijkstra once said, you should never start writing a program until you understand what output it should produce. You need to generate HTML from your XML.

I would start by hand-crafting the HTML that you want to produce, and checking that this HTML works as expected in the browser. Then that defines the target of your transformation. If you don't know how to write the HTML, then you need to learn some HTML. Once you have worked out what HTML you need to produce, come back here and ask questions about how to produce it.
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference
  #9 (permalink)  
Old January 27th, 2010, 04:23 PM
Authorized User
 
Join Date: Jan 2010
Posts: 33
Thanks: 13
Thanked 0 Times in 0 Posts
Default

Michael,

I am trying to learn XSLT and had just found out that like you pointed out that the whole thing can be done easily in XML/XSLT. But the people have me do this wants from me both a XSL file and a ASP.NET file so I take it they want to use ASP.NET controls vs. HTML. With that said do you think it does make sense to convert to attributes? What is your take? Thanks.
  #10 (permalink)  
Old January 27th, 2010, 04:27 PM
mhkay's Avatar
Wrox Author
Points: 18,274, Level: 58
Points: 18,274, Level: 58 Points: 18,274, Level: 58 Points: 18,274, Level: 58
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,932
Thanks: 0
Thanked 282 Times in 277 Posts
Default

If you don't understand the requirements that you have been given then you should ask the people who defined the requirements for clarification.

I would imagine they want to see an ASP.NET program that invokes the XSLT transformation on the selected source document in response to some request from a browser.
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference
The Following User Says Thank You to mhkay For This Useful Post:
jtnchang (January 27th, 2010)
 


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Regarding xml-html transformation of an xml string using xslt and javascript suprakash444 XSLT 1 January 12th, 2009 01:23 AM
xml transformation spring152103 XSLT 9 October 14th, 2008 08:50 PM
Is XML supports transformation of HTML to XML? zeeonline XSLT 1 July 28th, 2006 06:13 PM
Transformation Question realgone_ SQL Server DTS 1 March 3rd, 2005 10:22 PM
XML to XML transformation using XSLT karjagis XSLT 3 July 30th, 2004 07:13 AM



All times are GMT -4. The time now is 08:17 AM.


Powered by vBulletin®
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.