473,320 Members | 1,722 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.

preserving markup

've got some javascript and HTML I want to enter directly into my xml
document. I've entered the JS and HTML content into a tag that's
defined as text in the schema. When I process my xml, the and < in
the JS and HTML are output as named entitles &lt; and &gt;. As a
result, this content is interpreted by the browser as page content
rather than code/markup to be processed and rendered.

I've tried using just the non-escaped content as well the following
templates but the named entities always appear in the output.

<xsl:template match="code">
<div style="MARGIN-LEFT: 30px">
<xsl:text disable-output-escaping="yes">&lt;![CDATA[ </
xsl:text>
<xsl:value-of select="."/>
<xsl:text disable-output-escaping="yes">]]&gt;</
xsl:text>
</div>
</xsl:template>

<xsl:template match="code">
<div style="MARGIN-LEFT: 30px">
<xsl:value-of select="." disable-output-escaping="yes"/>
</div>
</xsl:template>

Any help would be appreciated!!

TIA,
David
Jun 27 '08 #1
5 1332
Disable-output-escaping should be an absolute last-resort solution;
there is almost always a better way.

If your stylesheet needs to force the content of some elements to be
output as a CDATA section to support broken downstream processing, use
xsl:output's cdata-section-elements attribute.

Though personally I consider that a hideous concept. No properly-written
downstream application should care whether you use <![CDATA[]]or
individually escape characters; semantically those two approaches are
exactly the same. I grant that some older tools are broken in this
regard, but ... yecch.

Jun 27 '08 #2
If your stylesheet needs to force the content of some elements to be
output as a CDATA section to support broken downstream processing, use
xsl:output's cdata-section-elements attribute.
Thanks for the quick response Joel. Not sure what you mean by 'broken
downstream processing'. I'm outputing HTML (and Javascript), not XML.
cdata-section-elements appears to be appropriate only where
method=xml. Perhaps I'm missing something?

Is this what you had in mind?

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/
Transform">
<xsl:output omit-xml-declaration="yes" method="html" cdata-section-
elements="code"/>
<xsl:template match="code">
<div style="MARGIN-LEFT: 30px">
<xsl:value-of select="." />
</div>
</xsl:template>
</xsl:stylesheet>
Jun 27 '08 #3
David Schwartz wrote:
If your stylesheet needs to force the content of some elements to be
>output as a CDATA section to support broken downstream processing, use
xsl:output's cdata-section-elements attribute.

Thanks for the quick response Joel. Not sure what you mean by 'broken
downstream processing'.
Browsers. Most (all?) of them are hopelessly broken when it comes to
handling XML. Fortunately...
I'm outputing HTML (and Javascript), not XML.
....in which case you can get away with it.

///Peter
--
XML FAQ: http://xml.silmaril.ie/
Jun 27 '08 #4

Thanks but you didn't address whether the output statement was what
was intended.
Jun 27 '08 #5
David Schwartz wrote:
I'm outputing HTML (and Javascript), not XML.
cdata-section-elements appears to be appropriate only where
method=xml. Perhaps I'm missing something?
Yes, <xsl:output cdata-section-elements="code"/was what I intended.

Some references (including Michael Kay's book, which is one of the best
hardcopy references I've seen for XSLT) do claim that
cdata-section-elements is marked as "not applicable to html output".
However, I've just rechecked and I don't see that restriction in the
XSLT Recommendation itself. All I can say is "try it, and if it doesn't
work ask the processor's authors why not."

But: No program ought to care whether you've used CDATA sections or
individual-character escaping; that distinction is purely a convenience
for humans. Any program which *insists* on one representation or the
other is not processing the documents as intended by their spec. There
are a few special cases where CDATA sections are worth considering --
mostly when the document source is intended to be hand-edited by humans
-- but even there I consider them excessively fragile. So I would also
beat up whoever wrote the code that is foisting this requirement upon you.
Jun 27 '08 #6

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

Similar topics

7
by: Jacek Generowicz | last post by:
:::Title::: A simple text markup utility :::/Title::: :::Section Introduction ::: I'm looking for something to help developers wirte documentation for bits of software they are writing. The...
30
by: Reinhold Birkenfeld | last post by:
Hello, I know that there are different YAML engines for Python out there (Syck, PyYaml, more?). Which one do you use, and why? For those of you who don't know what YAML is: visit...
0
by: MarionEll | last post by:
Montreal in August: what could be better? Great food, great coffee, and a funky hotel full of markup geeks! CALL FOR PARTICIPATION EXTREME MARKUP LANGUAGES 2004 ABOUT THE CONFERENCE ...
0
by: MarionEll | last post by:
--------------------------------------------------------- ************* Complete Program Available ************** ************ Late Breaking Sessions Added ************* *********** Extreme...
38
by: Jukka K. Korpela | last post by:
As well all know, valid markup is important... but when trying to find a convincing modern argument in favor of this, I found pages like http://www.htmlhelp.com/tools/validator/reasons.html which...
47
by: Andy Dingley | last post by:
Assume an English language page, linking to a foreign history resource that's only available in a foreign language. Any suggestions on appropriate "best practice" markup, particularly regarding the...
16
by: TTroy | last post by:
Hello, I'm relatively new to C and have gone through more than 4 books on it. None mentioned anything about integral promotion, arithmetic conversion, value preserving and unsigned preserving. ...
3
by: sophia.agnes | last post by:
Dear all, I was going through the book "C a software engineering approach by darnell & Margolis" there was a section named sign preserving vs value preserving it is as follows sign...
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
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
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...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
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...
1
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...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
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.