Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > preserving markup

Reply
Thread Tools

preserving markup

 
 
David Schwartz
Guest
Posts: n/a
 
      06-06-2008
'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
 
Reply With Quote
 
 
 
 
Joseph J. Kesselman
Guest
Posts: n/a
 
      06-06-2008
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
xslutput'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.

 
Reply With Quote
 
 
 
 
David Schwartz
Guest
Posts: n/a
 
      06-06-2008
If your stylesheet needs to force the content of some elements to be
> output as a CDATA section to support broken downstream processing, use
> xslutput'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" xmlnssl="http://www.w3.org/1999/XSL/
Transform">
<xslutput 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>
 
Reply With Quote
 
Peter Flynn
Guest
Posts: n/a
 
      06-07-2008
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
>> xslutput'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/
 
Reply With Quote
 
David Schwartz
Guest
Posts: n/a
 
      06-09-2008

Thanks but you didn't address whether the output statement was what
was intended.
 
Reply With Quote
 
Joseph J. Kesselman
Guest
Posts: n/a
 
      06-09-2008
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, <xslutput 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.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Sign preserving Vs value preserving sophia.agnes@gmail.com C Programming 4 12-07-2007 03:14 PM
integral promotion, arithmetic conversion, value preserving, unsigned preserving??? TTroy C Programming 16 01-31-2005 10:20 PM
Viewing the output of a form post and preserving authentication Jeremy Phillips Perl 2 08-04-2004 05:42 PM
Viewing the output of a form post and preserving authentication Jeremy Phillips Perl 1 07-23-2004 03:05 PM
Server.Transfer To Same Page Not Preserving Control Values Pete ASP .Net 2 06-11-2004 12:13 PM



Advertisments