Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > Display raw XML file in HTML file via XSL

Reply
Thread Tools

Display raw XML file in HTML file via XSL

 
 
Stefan Schulze Frielinghaus
Guest
Posts: n/a
 
      06-25-2008
Hello everyone,

I would like to convert a XML file to show up in a HTML file. Up till
now I do that via sed to replace "<>&" with &gt; etc. and afterwords I
embed the code in the HTML file. But now I switched to XML and XSL and
hoped that there is a way to do that automatically. My intend is to
display a XML file in a browser just like as in an ASCII-editor.

Is there something like this pseudo-code:

<pre>
<![CDATA[<xsl:copy-of select="document('test.xml')"/>]]>
</pre>

Just import a XML file and replace the tags so that a browser can display it.

Best regards
Stefan

 
Reply With Quote
 
 
 
 
Joseph J. Kesselman
Guest
Posts: n/a
 
      06-25-2008
> Is there something like this pseudo-code:
> <pre>
> <![CDATA[<xsl:copy-of select="document('test.xml')"/>]]>
> </pre>
> Just import a XML file and replace the tags so that a browser can display it.


Not directly in XSLT 1.0, though folks have written "xml serializer
transformations" which achieve it. (Basically, use modes to switch to a
set of templates which renders the node tree as text equivalents.) I
don't have a pointer handy, but searching archives of this newgroup
and/or searching the web should find one or two of these. Making this
kluge work properly for namespaced documents is Significantly Harder
than just doing the most primitive version; you may want to look at the
DOM Level 3 spec and consider adopting its serialiazation/fixup approaches.

Note that a CDATA section doesn't actually buy you anything for this
purpose. If the stylesheet is generating the text, it's the stylesheet's
job to escape it appropriately to make it legal XML and the right things
should happen. Whether that's done with <![CDATA[]]> or by escaping
individual characters shouldn't matter, though the latter may be a bit
easier for humans to read.

I don't _think_ XSLT 2.0 adds anything which makes this task easier, but
I haven't checked recently.

 
Reply With Quote
 
 
 
 
Stefan Schulze Frielinghaus
Guest
Posts: n/a
 
      06-29-2008
On Wed, 2008-06-25 at 15:04 -0400, Joseph J. Kesselman wrote:
[...]
> Not directly in XSLT 1.0, though folks have written "xml serializer
> transformations" which achieve it. (Basically, use modes to switch to a
> set of templates which renders the node tree as text equivalents.)


I hoped you didn't say that

> I don't have a pointer handy, but searching archives of this newgroup
> and/or searching the web should find one or two of these. Making this
> kluge work properly for namespaced documents is Significantly Harder
> than just doing the most primitive version; you may want to look at the
> DOM Level 3 spec and consider adopting its serialiazation/fixup approaches.


I found one which is pretty simple to use and produces a nice output. If
someone else is interested here is the link:
http://www.xmlportfolio.com/xml-to-string/

 
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
XSL: putting a XSL value inside an html attribute? Kourosh XML 6 05-17-2006 09:13 PM
XSL Question tp xsl:for-each and xsl:variable schaf@2wire.ch XML 1 05-27-2005 09:25 PM
mixing raw xml display w/ formated display blank101 XML 2 02-05-2005 03:10 PM
Reading XML file via XSL shailesh_gaikar@indiatimes.com XML 6 01-27-2005 08:04 PM
CHtmlView: How to read html text before display, change and give to display changed html code? Marek Kurowski C Programming 1 08-18-2004 06:41 PM



Advertisments