473,320 Members | 1,904 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

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 1708
"Jim Bancroft" <bo*********@nowhere.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>...<br/>...</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;br/&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.nag.co.uk...
"Jim Bancroft" <bo*********@nowhere.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>...<br/>...</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:apply-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:apply-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
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...
2
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...
2
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...
18
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...
8
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...
1
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...
3
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...
4
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>...
4
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...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.