Display raw XML file in HTML file via XSL

  • Thread starter Stefan Schulze Frielinghaus
  • Start date
S

Stefan Schulze Frielinghaus

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
 
J

Joseph J. Kesselman

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.
 
S

Stefan Schulze Frielinghaus

]
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/
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,020
Latest member
GenesisGai

Latest Threads

Top