Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > how to use xsl to escape code blocks

Reply
Thread Tools

how to use xsl to escape code blocks

 
 
andrew_nuss@yahoo.com
Guest
Posts: n/a
 
      02-09-2007
Hi,

I have a <code> tag for my xml file and plan to have code snippets
that contain lots of < > and & metacharacters. That's not tough to
put in xml because I'll just wrap in a CDATA section.

However, I need to use xsl to spit out HTML <pre> tag with the code
block and obviously to
use HTML escapes for < > and &. What's the easiest way to get XSL to
escape the necessary characters
found in the PCDATA of my <code> tag?

Thanks,
Andy

 
Reply With Quote
 
 
 
 
Joe Kesselman
Guest
Posts: n/a
 
      02-09-2007
> However, I need to use xsl to spit out HTML <pre> tag with the code
> block and obviously to
> use HTML escapes for < > and &. What's the easiest way to get XSL to
> escape the necessary characters
> found in the PCDATA of my <code> tag?


Have you tried it yet? An XSLT processor in HTML output mode should
escape those characters appropriately...

As far as outputting the <pre> -- that's just like any other element;
just set up the stylesheet so when it sees <code> it knows it needs to
translate that into <pre>.

--
() ASCII Ribbon Campaign | Joe Kesselman
/\ Stamp out HTML e-mail! | System architexture and kinetic poetry
 
Reply With Quote
 
 
 
 
andrew_nuss@yahoo.com
Guest
Posts: n/a
 
      02-09-2007

> Have you tried it yet? An XSLT processor in HTML output mode should
> escape those characters appropriately...
>
> As far as outputting the <pre> -- that's just like any other element;
> just set up the stylesheet so when it sees <code> it knows it needs to
> translate that into <pre>.
>


Thanks for the feedback. I omitted part of the problem requirement:
I also have an <asis> XML file tag, which contains a large block of
HTML that I need to NOT escape, that is, drop in as it is.

So could someone clarify how to use the modes of (1) having a CDATA
wrapped tag content that gets escaped when I spit out the <pre> tag
wrapper, (2) how do an <asis> tag which contains CDATA with lots of
tags that I don't want escaped. Maybe some sample XSL code.

Thanks, Andy

 
Reply With Quote
 
Joe Kesselman
Guest
Posts: n/a
 
      02-09-2007
http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:
> (2) how do an <asis> tag which contains CDATA with lots of
> tags that I don't want escaped.


Emphatically not a recommended solution. Instead, have the <asis> tag
instead contain real XHTML and just render that out as HTML. Far simpler.

If you absolutely must perform this particular obscenity -- ie, because
your customer refuses to accept recommendations to address the problem
properly -- you can try using the Disable Output Escaping mechanism to
tell the XSLT processor that content of a particular element should be
rendered unchanged. This will not work in all processing environments,
but it's the closest available to what you're looking for. See

http://www.w3.org/TR/1999/REC-xslt-1...utput-escaping

The cdata-section-elements attribute of xslutput may (or may not) also
be worth looking at.

.... But I say again: This is a foot-seeking gun. If you want to keep
your toes intact, learn not to use it.


--
() ASCII Ribbon Campaign | Joe Kesselman
/\ Stamp out HTML e-mail! | System architexture and kinetic poetry
 
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
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
How to read strings cantaining escape character from a file and useit as escape sequences? slomo Python 5 12-02-2007 11:39 AM
XSL Question tp xsl:for-each and xsl:variable schaf@2wire.ch XML 1 05-27-2005 09:25 PM
procs/blocks - blocks with procs, blocks with blocks? matt Ruby 1 08-06-2004 01:33 AM



Advertisments