RE: HTML in an XML tag
Michael, Right I understand, unfortunately when I came on board here, this was in place for 2 years and trying to get it changed... well... you know what I mean. :-) I have disable-output-escaping="yes" on a lot of my XSL's but I'm needing to have these tags doing what they need to do in the text that you see. Thanks to everyone for their help! Mac [[Michael Kay]] 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 <br> 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 & or < that represent real characters, not HTML markup, then the browser might get confused. Such characters should be double-escaped as &amp; and &lt;. Michael Kay Software AG home: Michael.H.Kay@xxxxxxxxxxxx work: Michael.Kay@xxxxxxxxxxxxxx [[Mac Rost]] > 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. <br> > 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é 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 > <br> -Aurora Mall 2 Miles <br> -Movie Theaters 4 Miles > <br> -Fidlers Green 10 Miles <br> -Park Meadows Mall 15 > Miles <br> -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: <br> Go > onto Pena Boulevard <br> Merge onto I-70 west <br> Go onto > I-225 South <br> 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. &lt;br&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 > "&lt;br&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='"&lt;br&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 XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
PURCHASE STYLUS STUDIO ONLINE TODAY!
Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!
Download The World's Best XML IDE!
Accelerate XML development with our award-winning XML IDE - Download a free trial today!
Subscribe in XML format