Display raw XML file in HTML file via XSL

Discussion in 'XML' started by Stefan Schulze Frielinghaus, Jun 25, 2008.

  1. 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
     
    Stefan Schulze Frielinghaus, Jun 25, 2008
    #1
    1. Advertising

  2. > 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.
     
    Joseph J. Kesselman, Jun 25, 2008
    #2
    1. Advertising

  3. 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/
     
    Stefan Schulze Frielinghaus, Jun 29, 2008
    #3
    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. Replies:
    6
    Views:
    540
  2. blank101
    Replies:
    2
    Views:
    536
    blank101
    Feb 5, 2005
  3. Replies:
    1
    Views:
    3,613
    A. Bolmarcich
    May 27, 2005
  4. Kourosh
    Replies:
    6
    Views:
    856
    Peter Flynn
    May 17, 2006
  5. Marek Kurowski
    Replies:
    1
    Views:
    999
    Mark A. Odell
    Aug 18, 2004
Loading...

Share This Page