Solved

Printing html decoded value from xslt on webpage

Posted on 2012-04-10
10
370 Views
Last Modified: 2012-04-12
Hi Experts,

My xml node <LongDescription> has html endoded string like below

<LongDescription>&lt;p&gt;&lt;strong&gt;Location:&lt;/strong&gt; Beverly Hills.&lt;/p&gt;
        &lt;p&gt;The Beverly Wilshire is at one of the world’s most famous intersections – Rodeo Drive and Wilshire Boulevard, with its exclusive shops, galleries and restaurants. The property features luxuriously appointed rooms, award-winning restaurants and lively entertainment. Many of the hotel’s guest rooms have spectacular views of Rodeo Drive, the Hollywood Hills and the L.A. skyline. Los Angeles International Airport is 29 kilometres away.&lt;/p&gt;
        &lt;p&gt;&lt;strong&gt;Facilities:&lt;/strong&gt; 395 rooms and suites. Two restaurants, bar, 24-hour room service, shop, hairdresser, beauty salon, safety deposit boxes, business centre, babysitting, interconnecting and non-smoking rooms.
&lt;br/&gt;
                &lt;br/&gt;
                &lt;strong&gt;Superior Rooms:&lt;/strong&gt; Air-conditioning, TV, CD, data ports, minibar and safe.
&lt;br/&gt;
                &lt;br/&gt;
                &lt;strong&gt;Sports and leisure:&lt;/strong&gt; Outdoor pool, fitness centre, spa, sauna, jacuzzi, steam bath and massage.&lt;/p&gt;
        &lt;p&gt;&lt;strong&gt;Check-in:&lt;/strong&gt; 1500 hours&lt;/p&gt;
        &lt;p&gt;&lt;strong&gt;Check-out:&lt;/strong&gt; 1200 hours.
&lt;br/&gt;&lt;/p&gt;</LongDescription>


When I am reading the text from xslt like below

<xsl:value-of select ="LongDescription" disable-output-escaping="yes" />

All html formating is not printing in the web page

Please can you help, so that format of the html in node <LongDescription> prints as is on web page

Please find attached my xml and xslt file

Please guide

Thanks
dcp248933-436029.xml
HotelListDynamic.xsl
0
Comment
Question by:tia_kamakshi
  • 6
  • 4
10 Comments
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 37828903
which html formatting are you missing?
and how do you view this?

If I run your XSLT against your XML (after correcting the obvious conbtext issue in the for-each)
I get exactly what I need... the layouted description

Or is it the context issue that is the problem?
In the for each you need to strip the path up to the level on the root element
line 13 should read
      <xsl:for-each select="Result/XmlContent">
if the XML you sent really is teh source
0
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 37828906
I would make that for-each an apply-templates by the way
0
 

Author Comment

by:tia_kamakshi
ID: 37829081
Thanks Gertone for your reply.

My I am not seeing formatting on my web page... I am loosing all formatting done.

I have provided you the actual xml and xslt

What can be the reason that I am loosing my formatting in my html?

Please guide

Thanks again
0
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 37829318
How do you view the results and how do you run the XSLT?

If this is the actual XML and XSLT you need to change the context in teh for-each as I indicated
0
 

Author Comment

by:tia_kamakshi
ID: 37829472
<LongDescription> node is printing on the html page but with no formatting

Please suggest
0
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
LVL 60

Expert Comment

by:Geert Bormans
ID: 37830086
again, how do you execute the XSLT and how do you view the results?

This is important information.
If for instance you are running this in FireFox or using the TransformiX XSLT processor,
this will not work simply because there is no support for disable-output-escaping there
d-o-e is not mandatory and some processors simply don't support it (and claim they never will)
In that particular case, you need to preprocess the lot to make it XML nodes instead of a text node prior to the XSLT
(and hope the html is wellformed XML)

so please tell me how you execute the XSLT and how you view the result
0
 

Author Comment

by:tia_kamakshi
ID: 37835816
Hi Gertone,

I applogise, Node <LongDescription> is written in xml file as below:

------------------------------------------------------------
<LongDescription>
<p>
<strong>Location:</strong> Beverly Hills1.</p>
<p>The Beverly Wilshire is at one of the world’s most famous intersections – Rodeo Drive and Wilshire Boulevard, with its exclusive shops, galleries and restaurants. The property features luxuriously appointed rooms, award-winning restaurants and lively entertainment. Many of the hotel’s guest rooms have spectacular views of Rodeo Drive, the Hollywood Hills and the L.A. skyline. Los Angeles International Airport is 29 kilometres away.</p>
<p>
<strong>Facilities:</strong> 395 rooms and suites. Two restaurants, bar, 24-hour room service, shop, hairdresser, beauty salon, safety deposit boxes, business centre, babysitting, interconnecting and non-smoking rooms.
<br></br>
<br></br>
<strong>Superior Rooms:</strong> Air-conditioning, TV, CD, data ports, minibar and safe.
<br></br>
<br></br>
<strong>Sports and leisure:</strong> Outdoor pool, fitness centre, spa, sauna, jacuzzi, steam bath and massage.</p>
<p>
<strong>Check-in:</strong> 1500 hours</p>
<p>
<strong>Check-out:</strong> 1200 hours.
<br></br>
</p>
</LongDescription>
------------------------------------------------------------

Please find correct xml attached.

In correct xslt, for-each loop is written as
<xsl:for-each select="Result/XmlContent">

In my webpage, html of long description is loosing html formatting, done in node
<LongDescription>

Please advice

Many Thanks again
dcp248933-436029.xml
HotelListDynamic.xsl
0
 
LVL 60

Accepted Solution

by:
Geert Bormans earned 500 total points
ID: 37836433
OK, this is a much better approach to control the html content in any case

by using value-of you just flatten out the text nodes
you need to procvess the children
I suggest we do that ion a special mode to not interfere with the other processing

change the value of into
                  <xsl:apply-templates select="LongDescription/node()" mode="preserve-html"/>  

and add a template

  <xsl:template match="node()" mode="preserve-html">
    <xsl:copy>
      <xsl:copy-of select="@*"/>
      <xsl:apply-templates select="node()" mode="preserve-html"/>
    </xsl:copy>
  </xsl:template>

Open in new window

0
 

Author Closing Comment

by:tia_kamakshi
ID: 37838996
This was great.Many Many Thanks for your great help

Regards,
0
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 37839007
welcome
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Merging XML files via VB Script 4 79
Create XML 5 46
Convert XML to excel12book 5 25
Shredding xml into an oracle 11g Database 2 31
The Client Need Led Us to RSS I recently had an investment company ask me how they might notify their constituents about their newsworthy publications.  Probably you would think "Facebook" or "Twitter" but this is an interesting client.  Their cons…
Many times as a report developer I've been asked to display normalized data such as three rows with values Jack, Joe, and Bob as a single comma-separated string such as 'Jack, Joe, Bob', and vice versa.  Here's how to do it. 
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now