Display an existing XML in browser as readable without modifying it.

Discussion in 'XML' started by rk, Jun 14, 2006.

  1. rk

    rk Guest

    I have the following library.xml file coming from a system, this can't
    be modified.
    ____________________________________________________________________________
    <?xml version="1.0" encoding="utf-8" standalone="no"?>
    <library>
    <book>
    <name>
    Discover America
    </name>
    </book>
    </library>
    ____________________________________________________________________________
    I need to be able to display the above file in browser in readable
    format. Here is the library.xsl.
    ____________________________________________________________________________
    <?xml version="1.0" encoding="ISO-8859-1"?>
    <xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:tns="http://www.ibm.com/websphere/crossworlds/2002/HierarchicalProperties"
    xmlns:fo="http://www.w3.org/1999/XSL/Format">
    <xsl:template match="/">
    <html>
    <head>
    </head>
    <body>
    <table border="3" bgcolor="white" cellspacing="1" cellpadding="1">
    <tr>
    <th>Book</th>
    </tr>
    <xsl:for-each select="library/book">
    <td>
    <xsl:value-of select="name"/>
    </td>
    </xsl:for-each>
    </tr>
    </xsl:for-each>
    </table>
    </body>
    </html>
    </xsl:template>
    </xsl:stylesheet
    ____________________________________________________________________________

    How can I present library.xml in readable format in browser without
    modifying the xml file itself?

    I have come across two options, which don't work.

    1) Add <?xml-stylesheet to refer library.xsl in library.xml. This
    doesn't work because I don't want to modify library.xml

    2) Create a new file libary_read.xml with the following content and
    open it in browser.

    <!DOCTYPE apage [
    <!ENTITY library SYSTEM "library.xml">
    ]>
    <readlibrary>
    &library;
    </readlibrary>

    And modify library.xsl to have <xsl:for-each
    select="readlibary/library/book">


    When I open this file in InternetExplorer, I get the following error.
    ________________________________________________________________________
    The standalone attribute cannot be used in external entities. Error
    processing resource 'file:///C:/Documents and Settings/...

    <?xml version="1.0" encoding="utf-8" standalone="no"?>
    ________________________________________________________________________

    I think having standalone="no" in library.xml is forcing me out of this
    option. If I remove standalone="no" it works. Since I can't modify
    library.xml, this option also gets ruled out.

    Regards,
    Rajesh Kamisetty
     
    rk, Jun 14, 2006
    #1
    1. Advertising

  2. rk

    Guest

    > How can I present library.xml in readable format in browser without
    > modifying the xml file itself?


    Rajesh,

    You could create a new xml file called temp.xml with the following
    content
    <?xml version="1.0" encoding="utf-8"?>
    <?xml-stylesheet type="text/xsl" href="library.xsl"?>
    <root/>

    The above file is just a dummy file, its main purpose being to load the
    books.xsl.

    Let us suppose that books.xml is the original xml file that you cannot
    change.

    Change library.xsl to the following stylesheet

    <?xml version="1.0" encoding="ISO-8859-1"?>
    <xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:tns="http://www.ibm.com/websphere/crossworlds/2002/HierarchicalProperties"
    xmlns:fo="http://www.w3.org/1999/XSL/Format">

    <xsl:template match="/">
    <xsl:apply-templates select="document('books.xml')/library" />
    </xsl:template>

    <xsl:template match="library">
    <html>
    <head>
    </head>
    <body>
    <table border="3" bgcolor="white" cellspacing="1" cellpadding="1">
    <tr>
    <th>Book</th>
    </tr>
    <tr>
    <xsl:for-each select="./book">
    <td>
    <xsl:value-of select="name"/>
    </td>
    </xsl:for-each>
    </tr>
    </table>
    </body>
    </html>
    </xsl:template>
    </xsl:stylesheet>

    So, you will have three files

    1)temp.xml - The dummy file to load the stylesheet.
    2)books.xml - The original file you cannot change
    3)library.xsl - The stylesheet that displays the table

    Opening temp.xml in a browser will give you the required output.

    -Dhanvanth
     
    , Jun 14, 2006
    #2
    1. Advertising

  3. Re: Display an existing XML in browser as readable without modifyingit.

    wrote:
    > Opening temp.xml in a browser will give you the required output.


    Note that this end-run shouldn't be necessary -- browsers *SHOULD* let
    the user mix source document and stylesheet arbitrarily to suit their
    own needs -- but unfortunately browser authors haven't caught up with
    this improved architecture yet.

    Pester whoever wrote yours, telling them you want this feature.


    --
    () ASCII Ribbon Campaign | Joe Kesselman
    /\ Stamp out HTML e-mail! | System architexture and kinetic poetry
     
    Joe Kesselman, Jun 15, 2006
    #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. Henry Townsend
    Replies:
    4
    Views:
    867
    Henry Townsend
    Oct 18, 2005
  2. nrm
    Replies:
    3
    Views:
    558
  3. Ed Keith
    Replies:
    2
    Views:
    358
    John Machin
    Dec 22, 2010
  4. Replies:
    0
    Views:
    201
  5. VA

    Modifying a existing function

    VA, Oct 24, 2005, in forum: Javascript
    Replies:
    4
    Views:
    106
    Ian Osgood
    Oct 24, 2005
Loading...

Share This Page