[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: HTML in an XML tag

Subject: RE: HTML in an XML tag
From: "Michael Kay" <michael.h.kay@xxxxxxxxxxxx>
Date: Thu, 5 Sep 2002 09:29:49 +0100
amp html
I don't think this is a good design: it's much better to hold XHTML
elements within your XML, and to make them explicit, that is:

<description>blah blah <xhtml:br/> blah blah</description>

rather than

<description>blah blah &lt;br&gt; blah blah</description>

But if you're stuck with handling the input in this form, you can get
the HTML output you want using disable-output-escaping="yes". The only
snags are:

(a) it might not work on all processors (e.g. not Netscape)
(b) it only works if you serialize the output, rather than passing it to
another phase of XML processing
(c) if your text also contains special characters such as &amp; or &lt;
that represent real characters, not HTML markup, then the browser might
get confused. Such characters should be double-escaped as &amp;amp; and
&amp;lt;.

Michael Kay
Software AG
home: Michael.H.Kay@xxxxxxxxxxxx
work: Michael.Kay@xxxxxxxxxxxxxx 


> -----Original Message-----
> From: owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx 
> [mailto:owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx] On Behalf Of Mac Rost
> Sent: 04 September 2002 23:09
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject: RE:  HTML in an XML tag
> 
> 
> 
> 
> Tom,
> I have tried this solution but was unable to make it work... 
> here is the
> whole xml file that's being used.
> ===================================================
> <HotelInfo>
>   <hotelID>122352</hotelID> 
>   <propertyType>H</propertyType> 
>   <rating>3.0</rating> 
>   <timeZone>MST</timeZone> 
>   <gmtOffset /> 
>   <yearPropertyOpened /> 
>   <yearPropertyRenovated /> 
>   <nativeCurrency>USD</nativeCurrency> 
>   <yearlyPropertyClosures /> 
>   <numberOfRooms>477</numberOfRooms> 
>   <numberOfSuites /> 
>   <numberOfFloors>12</numberOfFloors> 
>   <checkInTime>3:00 PM</checkInTime> 
>   <checkOutTime>12:00 PM</checkOutTime> 
>   <areaServed>AURORA</areaServed> 
>   <locationDescription>Primary Property Location - City Den Airport 20
> Mi Se Primary Airport - Den Distance From The Airport To Property - 20
> Mi Free Shuttle From Airport To Property Available Hours Of 
> Operation -
> From 0hrs To 2400hrs **Denver International Airport** -Complimentary
> Shuttle Van -Hours 0600-2300 Runs Every 60 Minutes Additional Forms Of
> Transportation From Primary Airport To Property - Rental Car -
> Enterprise Car Rental Located Onsite. Bus Or Other 
> Transportation - Nine
> Mile Park And Ride Is .25 Miles From The Hotel. Bus Information Name-
> Rtd Located 0.5 Miles Or 5 Minutes West. Additional Forms Of
> Transportation From City Center To Property - Taxi Rental Car -
> Enterprise Car Rental Located On The Main Level With Great Discount To
> Our Guests. Cars On-Site. For Advance Reservations Call 720-748-6939.
> Rail Or Subway - -*Union Station* 0.5 Miles 20 Minutes W Bus Or Other
> Transportation - -*Nine Mile Park Ride Bus Station* .25 Miles 5min E
> Driving Directions To The Property - From South - From Denver 
> Take I-25
> South To I-225 North. I-225 North To The Parker Road Exit. Turn Right
> Onto Parker. Stay In The Right Lane To Dam Road. Turn Right 
> On Dam Road
> To S. Vaughn Way. Turn Right On S. Vaughn Way. Hotel Is On Your
> Left.</locationDescription> 
>   <propertyDescription>The award-winning Radisson Hotel 
> Denver Southeast
> - Tech Center is conveniently located in the southeast Denver metro
> area, 22 miles from Denver International Airport. The Radisson Hotel
> Denver Southeast holds two State Company of the Year awards and two
> consecutive Culinary Excellence Awards. Stop by the trophy 
> cases in the
> main lobby. Adjacent to the 4,000-acre Cherry Creek State Park, this
> hotel is easily accessible to many of Denver's attractions. &lt;br&gt;
> The hotel features 477 beautifully appointed guest rooms. Take in the
> panoramic views of Denver, the Rocky Mountains and the Cherry Creek
> State Park from many of the rooms. Enjoy hiking, biking, swimming,
> picnicking, horseback riding, boating and more within a short distance
> from the hotel. The Aspen Caf&#233; located in the main lobby serves
> full breakfast, lunch and dinner menus seven days a week. The Radisson
> Hotel Denver Southeast - Tech Center is known for professional meeting
> services and award-winning banquet food and beverage 
> services. The hotel
> is convenient to dining, shopping and entertainment
> venues.</propertyDescription> 
>   <airportDescription /> 
>   <rateDisclaimer /> 
>   <guaranteePolicy>-07dec01 - 31dec10 Mon-Sun Guarantee Required For
> Late Arrival Guarantee Required For All Reservations 30 Days Prior To
> Arrival Because The Guarantee Policy May Vary By Rate Please See
> Individual Rate Details/rate Rules For Guarantee Policy.
> Accepted</guaranteePolicy> 
>   <cancellationPolicy>-07dec01 - 31dec10 - Cancel By 1800 Hours Local
> Hotel Time To Avoid A Cancellation Penalty Because The Cancellation
> Policy May Vary By Rate Please See Individual Rate Details/rate Rules
> For Cancellation Policy.</cancellationPolicy> 
>  
> <guaranteeCreditCardsAccepted>AX,CA,CB,DC,DS,JC,VI</guaranteeC
> reditCards
> Accepted> 
>  
> <depositCreditCardsAccepted>AX,CA,CB,DC,DS,JC,VI</depositCredi
> tCardsAcce
> pted> 
>   <areaInformation>Area Attractions: -Cherry Creek State Park 1 Block
> &lt;br&gt; -Aurora Mall 2 Miles &lt;br&gt; -Movie Theaters 4 Miles
> &lt;br&gt; -Fidlers Green 10 Miles &lt;br&gt; -Park Meadows Mall 15
> Miles &lt;br&gt; -Downtown Denver 20 Miles</areaInformation> 
>   <roomInformation>Bed Type: 2QN Short Description: Quad 
> Occupancy Long
> Description: Air Conditioning Alarm Clock Radio Bathrobe - Business
> Level Coffee/Tea maker Desk Electronic Door Locks Hair Dryer Handicap
> Accessible Iron/Ironing Board Mini Bar - Some Rooms Modem/Data Port
> Connection On Command Movies Refrigerator - Some Rooms Remote Control
> Color Cable TV Special Bathroom Amenities Voicemail Bed Type: 1KG/1QN
> Short Description: Standard 1-2 Persons Long Description: Air
> Conditioning Alarm Clock Radio Bathrobe - Business Level Coffee/Tea
> maker Desk Electronic Door Locks Hair Dryer Handicap Accessible
> Iron/Ironing Board Mini Bar - Some Rooms Modem/Data Port Connection On
> Command Movies Refrigerator - Some Rooms Remote Control Color Cable TV
> Special Bathroom Amenities Voicemail Bed Type: 2QN Short Description:
> Triple Occupancy Long Description: Air Conditioning Alarm Clock Radio
> Bathrobe - Business Level Coffee/Tea maker Desk Electronic Door Locks
> Hair Dryer Handicap Accessible Iron/Ironing Board Mini Bar - 
> Some Rooms
> Modem/Data Port Connection On Command Movies Refrigerator - Some Rooms
> Remote Control Color Cable TV Special Bathroom Amenities
> Voicemail</roomInformation> 
>   <propertyInformation>On-Site Facilities - * Front Desk * Gift Shop *
> Laundromat * Non-Smoking Rooms * Whirlpool Off-Site Facilities - *
> Elevators 19 Meeting/banquet Rooms In Over 25000 Square Ft Of Upscale
> Space. Two Ballrooms. Audio Visual Service On Site For All Meeting
> Rooms. Off-Site Recreations - * Football * Golfing * Museum/gallery
> Viewing * Night Clubs * Shopping * Sports Events * Tennis * Theater *
> Water Sports On-Site Services - * Express Check-In * Handicap 
> Services *
> Limited Room Service * Wake-Up Calls Hotel Features Fax And Copier
> Services For A Nominal Fee.</propertyInformation> 
>   <hotelPolicy>Extra Child - 0.00 Usd Rollaway For Child - 10.00 Usd
> Rates Are Guaranteed No Pets Allowed Extended Stay Option Available -
> Radisson Hotels And Resorts Offers A Corporate Rate To Corporate
> Travellers. To Secure The Corporate Rate At A Radisson 
> Hotel-Please Book
> The Cor Category. If Your Agency Receives A Special Rate At Radisson
> Hotels Please Request The Rate By Using Your Reserved Rate 
> Access Code.
> If Your Client Receives A Special Negotiated Rate Through 
> Their Company
> You Must Use The Rate Access Code For The Company Or Put In 
> The Cd Field
> In Order To Receive The Rate. Do Not Put Your Iata Number In 
> Your Cd Or
> Si Field. This Will Cause Your Reservation To Reject Automatically.
> 10.00 Pct Commission</hotelPolicy> 
>   <drivingDirections>From Denver International Airport: &lt;br&gt; Go
> onto Pena Boulevard &lt;br&gt; Merge onto I-70 west &lt;br&gt; Go onto
> I-225 South &lt;br&gt; Exit at Parker Road.</drivingDirections> 
>   <hotelName>RADISSON HOTEL DENVER</hotelName> 
>   <address1>3200 S. PARKER ROAD</address1> 
>   <address2 /> 
>   <address3 /> 
>   <city>AURORA</city> 
>   <stateProvince>CO</stateProvince> 
>   <country>US</country> 
>   <postalCode>80014</postalCode> 
>   <lowRate>65.95</lowRate> 
>   <highRate>119.95</highRate>
> </HotelInfo>
> 
> 
> [Mac Rost]
> 
> [[
> I would like to find a solution to this.... in the following XML tag,
> there is a standard HTML <br> within the paragraph. I was wondering if
> there was a way to incorporate the tag into the transformation.
> -----------------
> <policy>HHonors points or related frequent traveler miles are not
> honored on guest rooms reserved via Hotels.com. &amp;lt;br&amp;gt; You
> must present a photo ID when checking in.
> ]]
> 
> Notice that there is not a "standard <br>" in there.  Rather, there is
> text
> that, when displayed on a browser, **looks like** a <br>.  I 
> assume that
> you
> would like an actual <br> element to be inserted.  You can do this
> provided
> that there is not going to be a variable amount of whitespace between
> the
> "b" and the (escaped) angle brackets.
> 
> The method is actually the same one to use for your second question,
> about
> separating by "Bed Type:", so I will just give the approach to the
> first,
> and you will be able to make it work for the second (I am 
> assuming that
> you
> mean to separate the sections by a <br/> element and not 
> contain them in
> separate elements, which would be harder to do).
> 
> The problem here is to detect where a particular string occurs, and
> wherever
> it does, replace it with something else.  You do not know the exact
> number
> of these marker strings that may be present
> 
> You can do this by means of a recursive template, one that 
> calls itself.
> You split the string at the separator, which in this case is
> "&amp;lt;br&amp;gt;", using substring-before() and substring-after().
> In
> between the two fragments you put your <br/> or whatever you 
> want to go
> there.  The rest of the string, the substring-after() part, you feed
> back to
> the template to repeat until there are no more separators present.
> 
> The slightly tricky part is that, if no separator is present,
> substring-before() returns not the whole string but nothing, 
> so you have
> to
> test for that case and handle it differently.
> 
> Here is the xslt to do this job.  I have wrapped the result in a
> "policy"
> element but of course you can use any element you want.  Obviously you
> could
> add one more parameter to insert anything, not just a <br/> element.
> 
> ===============================================
> <xsl:template match='policy'>
> <policy>
> <!-- Call the recursive string splitter -->
>  <xsl:call-template name='break-at-string'>
>     <xsl:with-param name='data' select='.'/>
>     <xsl:with-param name='separator' select='"&amp;lt;br&amp;gt;"'/>
>  </xsl:call-template>
> </policy>
> </xsl:template>
> 
> <xsl:template name='break-at-string'>
>    <xsl:param name='data'/>
>    <xsl:param name='separator'/>
> 
>   <xsl:variable name='first'
> select='substring-before($data,$separator)'/>
>   <xsl:variable name='rest' 
> select='substring-after($data,$separator)'/>
> 
>  <xsl:choose>
>      <!-- When there is another separator in the string, display
>             the first part then call ourself to process the rest  -->
>     <xsl:when test='$rest'>
>        <xsl:value-of select='$first'/><br/>
>        <xsl:call-template name='break-at-string'>
>             <xsl:with-param name='data' select='$rest'/>
>             <xsl:with-param name='separator' select='$separator'/>
>        </xsl:call-template>
>    </xsl:when>
> 
>    <!-- If there are no more separators, we are done -->
>    <xsl:otherwise>
>        <xsl:value-of select='$data'/>
>    </xsl:otherwise>
>  </xsl:choose>
> </xsl:template>
> 
> ===============================================
> 
> Cheers,
> 
> Tom P
> 
> 
>  XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
> 
> 
>  XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
> 


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.