Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 22nd, 2010, 06:19 AM
Authorized User
 
Join Date: Jan 2010
Posts: 33
Thanks: 13
Thanked 0 Times in 0 Posts
Default How to transfrom multi-layered elements to attributes

Hi Michael,

How do I transform this multi-layered xml file if all I need are just name, shortdescription and Rateinfo elements. Below is my xml file,

<Motels>
<Motel>
<motelId>109277</motelId>
<name>Lincoln Motel</name>
<address1>870 7th Ave</address1>
<address2/>
<address3/>
<city>Monterey</city>
<stateProvince>CA</stateProvince>
<country>US</country>
<postalCode>91755</postalCode>
<airportCode>LAX</airportCode>
<lowRate>99.0</lowRate>
<highRate>199.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 Motel is located in New York, N.Y.</shortDescription>
<thumbNailUrl>/motels/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>
<motelInDestination>false</motelInDestination>
<referenceProximityDistance>-1.0</referenceProximityDistance>
<referenceProximityUnit/>
<MotelProperty>
<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>199.0</displayNightlyRate>
<displayNightlyRate>99.0</displayNightlyRate>
</DisplayNightlyRates>
<displayRoomRate>825.41</displayRoomRate>
<chargeableRoomRateTotal>825.41</chargeableRoomRateTotal>
<chargeableRoomRateTaxesAndFees>127.41</chargeableRoomRateTaxesAndFees>
<nativeCurrencyCode>USD</nativeCurrencyCode>
<NativeNightlyRates size="2">
<nativeNightlyRate>199.0</nativeNightlyRate>
<nativeNightlyRate>99.0</nativeNightlyRate>
</NativeNightlyRates>
<nativeRoomRate>825.41</nativeRoomRate>
<rateFrequency>B</rateFrequency>
</RateInfo>
<PromoRateInfo>
<displayCurrencyCode>USD</displayCurrencyCode>
<DisplayNightlyRates size="2">
<displayNightlyRate>199.0</displayNightlyRate>
<displayNightlyRate>99.0</displayNightlyRate>
</DisplayNightlyRates>
<displayRoomRate>825.41</displayRoomRate>
<chargeableRoomRateTotal>825.41</chargeableRoomRateTotal>
<chargeableRoomRateTaxesAndFees>127.41</chargeableRoomRateTaxesAndFees>
<nativeCurrencyCode>USD</nativeCurrencyCode>
<NativeNightlyRates size="2">
<nativeNightlyRate>199.0</nativeNightlyRate>
<nativeNightlyRate>99.0</nativeNightlyRate>
</NativeNightlyRates>
<nativeRoomRate>825.41</nativeRoomRate>
<rateFrequency>B</rateFrequency>
</PromoRateInfo>
</MotelProperty>
</Motel>
</Motels>

Thanks,
 
Old January 22nd, 2010, 06:29 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

Try

<xsl:template match="Motel">
<xsl:copy>
<xsl:copy-of select="name | shortDescription | MotelProperty/RateInfo"/>
</xsl:copy>
</xsl:template>
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference
 
Old January 22nd, 2010, 06:31 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

Sorry, I just saw that the title of your post contains information not present in the body.

I don't understand how you want to transform the RateInfo element into an attribute. Please show your desired output.
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference
 
Old January 22nd, 2010, 06:33 AM
Authorized User
 
Join Date: Jan 2010
Posts: 33
Thanks: 13
Thanked 0 Times in 0 Posts
Smile

Thanks Michael. That was quick and I did not know it was this simple.
 
Old January 23rd, 2010, 06:18 AM
Authorized User
 
Join Date: Jan 2010
Posts: 33
Thanks: 13
Thanked 0 Times in 0 Posts
Default

Michael,

RateInfo is a grand child of hotel element not a child so your earlier reply did not work. Along with name, address1 and shortdescription, I want RateInfo to become the fourth of all the attributes of hotel template. Is that possible? Also Michael, I asked you about making hotelId the Key of the hotel template but it did not work either. My objective is to transform this source xml to a attribute based xml and I need to extract data off one hotel element based on the key and dump into a asp:label control. Please help. Thanks.
 
Old January 23rd, 2010, 10:37 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

I asked you to show a sample of your desired output because I can't see how you would turn RateInfo, which has a lot of internal structure, into an attribute. So please give the information I asked for, don't just ask the same question again.
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference
 
Old January 23rd, 2010, 06:18 PM
Authorized User
 
Join Date: Jan 2010
Posts: 33
Thanks: 13
Thanked 0 Times in 0 Posts
Default

Michael,

My apologies for answering your question earlier. I was not fully aware of the structure in RateInfo and my requirement is to display that element along with the other simple elements in my asp.net control. So I don't have the output except I can only assume it being something like this

RateInfo :
displayCurrencyCode : USD
displayNightlyRate : 399.0
displayNightlyRate : 299.0
displayRoomRate : 799.7
chargeableRoomRateTotal : 799.7
chargeableRoomRateTaxesAndFees : 101.7
nativeCurrencyCode : USD
nativeNightlyRate : 399.0
nativeNightlyRate : 299.0
nativeRoomRate : 799.7
rateFrequency : B

Let me know if this is clear enough. Thanks.

James
 
Old January 23rd, 2010, 06:32 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

I now have no idea at all what your requirement is. You'll have to find a way of expressing it more clearly. There's no point writing code until you know what your program is supposed to do.
__________________
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 23rd, 2010)
 
Old January 23rd, 2010, 07:05 PM
Authorized User
 
Join Date: Jan 2010
Posts: 33
Thanks: 13
Thanked 0 Times in 0 Posts
Default

Michael,

I know these elements are children of RateInfo, which is tied to the dataset by the key hotelId. So I think it works for me if you can output the RateInfo as an attribute with these sub-attributes separated by a comma. This way when I code the query SELECT * FROM hotel WHERE hotleId = somecontrol.selectedValue I can pickup all four attributes including hotel name, address, shortdescription and RateInfo. Please let me know if you need more detailed clarification. Thanks.
 
Old January 23rd, 2010, 08:15 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

I now get the impression that when you say "attribute", you are not using the word with the XML meaning of the term.

Are you trying to output XML, HTML, or text?
__________________
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 23rd, 2010)





Similar Threads
Thread Thread Starter Forum Replies Last Post
Multi Layered Design jumbojs BOOK: Beginning C# 2005 Databases 1 October 19th, 2008 11:29 AM
Using xml elements as html attributes chipmaster XSLT 4 June 26th, 2007 10:22 AM
sequenced elements to attributes zkent XSLT 0 April 19th, 2006 08:50 AM
Elements and attributes Morrislgn XSLT 1 June 20th, 2005 11:13 AM
Elements w same name and their attributes supafly XSLT 1 May 30th, 2005 06:34 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.