 |
| 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
|
|
|
|

January 22nd, 2010, 06:19 AM
|
|
Authorized User
|
|
Join Date: Jan 2010
Posts: 33
Thanks: 13
Thanked 0 Times in 0 Posts
|
|
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>&lt;b&gt;Location.&l t;/b&gt;&lt;br /&gt; &lt;UL&gt;&lt;LI&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,
|
|

January 22nd, 2010, 06:29 AM
|
 |
Wrox Author
|
|
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
|
|
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
|
|

January 22nd, 2010, 06:31 AM
|
 |
Wrox Author
|
|
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
|
|
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
|
|

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

January 23rd, 2010, 06:18 AM
|
|
Authorized User
|
|
Join Date: Jan 2010
Posts: 33
Thanks: 13
Thanked 0 Times in 0 Posts
|
|
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.
|
|

January 23rd, 2010, 10:37 AM
|
 |
Wrox Author
|
|
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
|
|
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
|
|

January 23rd, 2010, 06:18 PM
|
|
Authorized User
|
|
Join Date: Jan 2010
Posts: 33
Thanks: 13
Thanked 0 Times in 0 Posts
|
|
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
|
|

January 23rd, 2010, 06:32 PM
|
 |
Wrox Author
|
|
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
|
|
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:
|
|
|

January 23rd, 2010, 07:05 PM
|
|
Authorized User
|
|
Join Date: Jan 2010
Posts: 33
Thanks: 13
Thanked 0 Times in 0 Posts
|
|
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.
|
|

January 23rd, 2010, 08:15 PM
|
 |
Wrox Author
|
|
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
|
|
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:
|
|
|
 |