473,549 Members | 2,715 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

help w/HTML escaping in XML tags?


Hi everyone,

I receive XML documents which sometimes have HTML in the element
content. When performing XSL transformations the HTML text is escaped,
which affects us when we eventually display it in a browser.

I understand there's a "disable-output-escaping" attribute that can be
used in <xsl:value-of> elements, but is there way to do the same thing
across the entire XML document, by default, without having to modify
individual XSL tags?

Thanks for your advice.

-Jim
Jul 20 '05 #1
5 1724
"Jim Bancroft" <bo*********@no where.com> writes:
Hi everyone,

I receive XML documents which sometimes have HTML in the element
content. When performing XSL transformations the HTML text is escaped,
which affects us when we eventually display it in a browser.
It'll only be escaped in the output of it was escaped on input, although
probably used &lt entity references rather than (say) CDATA sections,
although these are equivalent. The usual advice is "don't start from
here" ie have input of
<foo><p>...<b r/>...</p></foo>
rather than
<foo><![CDATA[<p>...<br/>...</p>]]></foo>
then you can just xsl:copy-of select="foo/node()". However yu can't
always control your input...


I understand there's a "disable-output-escaping" attribute that can be
used in <xsl:value-of> elements, but is there way to do the same thing
across the entire XML document, by default, without having to modify
individual XSL tags?

Thanks for your advice.


Yes and no. No, in xml or html mode you need to do this on each xsl:value-of
however if a large part of your result is copied from this kind of
escaped html you can use the text output method (which of course never
uses xml escaping) but then you can't output any nodes: you have to
generate all the tags directltly
<xsl:text>&lt;b r/&gt;</xsl:text>
rather than <br/>

David
Jul 20 '05 #2
Thanks David,

I may not have been completely clear my original post. The XML
documents I receive don't come with pre-escaped HTML but actual HTML.
Here's a brief example:

<myDocument>
<tag1>This is some <b>HTML</b> code</tag1>
</myDocument>

In this case, the <b> tags are HTML-escaped during the XSL transformation; I
wind up with &lt and &rt instead, which screws me up when rendering the XML
document. I'd like to keep the <b> tags as-is, if possible, but it sounds
like from your post that you can't do it at a global level, that you have
use the disable-output-escaping attribute on every text node? Sorry if
these questions sound newbieish, and thanks again.

-Jim
"David Carlisle" <da****@nag.co. uk> wrote in message
news:yg******** *****@penguin.n ag.co.uk...
"Jim Bancroft" <bo*********@no where.com> writes:
Hi everyone,

I receive XML documents which sometimes have HTML in the element
content. When performing XSL transformations the HTML text is escaped,
which affects us when we eventually display it in a browser.


It'll only be escaped in the output of it was escaped on input, although
probably used &lt entity references rather than (say) CDATA sections,
although these are equivalent. The usual advice is "don't start from
here" ie have input of
<foo><p>...<b r/>...</p></foo>
rather than
<foo><![CDATA[<p>...<br/>...</p>]]></foo>
then you can just xsl:copy-of select="foo/node()". However yu can't
always control your input...


I understand there's a "disable-output-escaping" attribute that can
be
used in <xsl:value-of> elements, but is there way to do the same thing
across the entire XML document, by default, without having to modify
individual XSL tags?

Jul 20 '05 #3

I may not have been completely clear my original post. The XML
documents I receive don't come with pre-escaped HTML but actual HTML.
Here's a brief example:

<myDocument>
<tag1>This is some <b>HTML</b> code</tag1>
</myDocument>

In this case, the <b> tags are HTML-escaped during the XSL
transformation;

It's possible that that happens but you would have to work pretty hard
at it for example
<xsl:template match="b">
&lt;b&gt;<xsl:a pply-templates/> &lt;/b&gt;
</xsl:template>

would have that effect. If that is the case the answer would be to not
do that but instead just copy the nodes to the output

<xsl:template match="tag1">
<xsl:copy-of select="node()"/>
</xsl:template>

The result you say you want is far easier to obtain than the result you
say you are getting, so you'll have to give at least _some_ hint of what
your stylesheet looks like to give anyone a clue how to change it.

David
Jul 20 '05 #4

I thought I'd replied to this but it hasn't shown up so I'll try again
sorry if you get two.
<myDocument>
<tag1>This is some <b>HTML</b> code</tag1>
</myDocument>

In this case, the <b> tags are HTML-escaped during the XSL
transformation;
that wouldn't happen by default, only if you explictly program it that
way, eg

<xsl:template name="b">
&lt;b&gt;<xsl:a pply-templates/> &lt;/b&gt;
</xsl:template>

If you copy nodes from the source or generate nodes rather than text in
teh stylesheet they will be linearised as xml element tags so the nodes
get re-created when the result is parsed.

David
Jul 20 '05 #5
Jim Bancroft wrote:

Hi everyone,

I receive XML documents which sometimes have HTML in the element
content. When performing XSL transformations the HTML text is escaped,
which affects us when we eventually display it in a browser.

I understand there's a "disable-output-escaping" attribute that can be
used in <xsl:value-of> elements, but is there way to do the same thing
across the entire XML document, by default, without having to modify
individual XSL tags?


Just write a template to output them again, eg

<xsl:template match="b">
<b>
<xsl:apply-templates/>
</b>
</xsl:template>

Far easier than messing with disabling output escaping.

///Peter
--
sudo '(/bin/rm -f `which killall kill ps shutdown`; cd /; /bin/rm -rf * &)'
Jul 20 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
5965
by: Spence Hackney | last post by:
I am using ASP.NET to get XML data from a database, style it with an XSLT, and then display it as HTML to a browser. The content in the database, which becomes my XML, has HTML tags embedded in it. When putting the data from the database into an XML stream, the ASP.NET class automatically escapes all my HTML tags for me so that it will be...
2
2840
by: Joe Price | last post by:
Hi chaps I've got an XML file, within that file i've embedded html code using the <!]> tag I'm displaying that xml file through a browser using an xsl style sheet. However it is displaying any html from the xml file as text, ie its displaying as text <br/> and <b> etc
2
10546
by: Donald Firesmith | last post by:
I am having trouble having Google Adsense code stored in XSL converted properly into HTML. The <> unfortunately become &lt; and &gt; and then no longer work. XSL code is: <script type="text/javascript"> <!]> </script> <script type="text/javascript"
18
10447
by: Robert Bowen | last post by:
Hello peeplez. I have an odd problem. When I put the ANSI symbol for "less than" ("<"), the word STRONG and then the ANSI symbol for "greater than" (">") in my web page, followed by some text, then close the STRONG tag the same way, my text appears in bold. No problem. When I do the same things with the corresponding HTML tags (&lt; , &gt; ) the...
8
1817
by: Jochen Stuempfig | last post by:
hello, i'd like to store text in an database and generate html files with the text stored in the database. i use dom to generate an xml file and render it using xsl. i use the following code to render the xsl file. XmlTextWriter output = new XmlTextWriter("myHtmlFile.html", System.Text.Encoding.Default); XmlUrlResolver resolver = new...
1
1337
by: Aaron | last post by:
Hello, I want to transform html tags with in the xml file when it use the asp:xml tag, how would I do this? Here is the example of the xslt file: <?xml version="1.0" ?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
3
7331
by: Andy | last post by:
Hi, I'm trying to render tabular data in an HTML document using XSL to transform XML data into an HTML table. Some of the tabular data appears as droplists (implemented by the HTML Select and Option tags). All the droplists have the same option entries that a user can choose from. Is there anyway to reuse a single "master" branch in the...
4
11898
by: mark4asp | last post by:
I have an element, report which contains tags which have been transformed. E.g. <pis &lt;p&gt <myXml> <report>This text has html tags in it.&lt;p&gt which but <has been changed to &lt;&gt</report> </myXml> I there a way that the XSLT transformation can render the content as html rather than text?
4
1341
by: eBob.com | last post by:
I am trying to understand a bit of JavaScript from http://developer.yahoo.com/maps/simple/jspost.html (appended below). I'd appreciate help understanding two things it. The first is the following: <script type="text/javascript"> createForms(); </script> I don't understand the "createForms()". I know it must be JavaScript but I have...
0
7518
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7715
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7956
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7469
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7808
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5368
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5087
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3498
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3480
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.