how to use xsl to escape code blocks

Discussion in 'XML' started by andrew_nuss@yahoo.com, Feb 9, 2007.

  1. Guest

    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
     
    , Feb 9, 2007
    #1
    1. Advertising

  2. > 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
     
    Joe Kesselman, Feb 9, 2007
    #2
    1. Advertising

  3. Guest


    > 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
     
    , Feb 9, 2007
    #3
  4. 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-19991116#disable-output-escaping

    The cdata-section-elements attribute of xsl:eek:utput 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
     
    Joe Kesselman, Feb 9, 2007
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Arjen
    Replies:
    3
    Views:
    446
    Scott Allen
    Feb 27, 2005
  2. Replies:
    1
    Views:
    3,611
    A. Bolmarcich
    May 27, 2005
  3. slomo
    Replies:
    5
    Views:
    1,545
    Duncan Booth
    Dec 2, 2007
  4. matt
    Replies:
    1
    Views:
    269
    George Ogata
    Aug 6, 2004
  5. Steven Taylor
    Replies:
    9
    Views:
    255
    Brian Candler
    Apr 27, 2009
Loading...

Share This Page