[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: store and output source-code-listings

Subject: Re: store and output source-code-listings
From: Mike Brown <mike@xxxxxxxx>
Date: Wed, 9 Apr 2003 01:43:33 -0600 (MDT)
output source code
jm wrote:
> can anybody give me a hint, how I can store code-listings (java, c++, ....)
> in my xml-file and put it out as html with XSLT?
> 
> It's just for showing some code-chunks on the website.
> 
> I tried to use <![CDATA[  ... code in here ]> but this doesn't work properly.
> I even need do recognize LF to format the output.

You can use CDATA sections in the XML, that's fine. Or you can replace all the
"<" with "&lt;" and "&" with "&amp;", which is all a CDATA section saves you
from having to do...

<code><![CDATA[

   text and <tags> & stuff

]]></code>

is the same as

<code>

   text and &lt;tags> &amp; stuff

</code>

Make sure you have <xsl:output method="html"/>, and copy the parsed
text through...

<xsl:template match="code">
  <pre>
    <xsl:value-of select="."/>
  </pre>
</xsl:template>


Your HTML output will have

<pre>

    text and &lt;tags> &amp; stuff

</pre>


The fact that it's in a <pre> will cause whitespace to be preserved when it is
rendered by the HTML user agent. The "&lt;" and "&amp;" are how the HTML
serializer in the XSLT processor decided to output the "<" and "&" in the
parsed data, in order to conform to HTML syntax. It will be parsed by the HTML
browser just like it would in XML, so you'll get "<" in the rendering, don't
worry. Fine-tune the rendering with CSS. No need to get fancy with replacing
linefeeds with <br>s since <pre> does all the work for you.

Mike

-- 
  Mike J. Brown   |  http://skew.org/~mike/resume/
  Denver, CO, USA |  http://skew.org/xml/



 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.