SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Guru Dashman's Avatar
    Join Date
    Jan 2006
    Location
    Manchester, UK
    Posts
    627
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Display content of XML file in (x)HTML page

    Hi guys ...

    I currently have the folowing situation:

    We have developed a series of xhtml templates for a client. Now, on one of the templates, they are going to be using a Flash movie, which itself is going to use XML for all of it's content. Thats fine. Now, they want to be able to use the same XML doc to display content to non-Flash pages (users with no Flash) so that they see the same content.

    In these pages, they want to use the same header, footer, top nav etc, but only have the content from the XML display in the main part of the page.

    I have little to no experience with XSL, and the only real experience I have with XML is creating XML with PHP from a db, so do not really know where to start with displaying and formatting this content.

    I have read about data islands, but these are only compatible with IE as far as I can tell.

    They are really keen on using the method mentioned above, as it would mean they only need to edit one XML file, but I think that is working backwards. I personally think the best solution is to store all the data in the database, and have it output XML in the format they desire for the Flash to use, and then output pure xhtml for the alternative content.

    Is it possible to format XML in an xhtml doc, whilst maintaining all the other xhtml page elements (header, footer etc) and still have valid (xhml strict) pages?

    If so, could somebody please advise as to how to go about this, or at least some starting points? I have used W3Schools' site a bit to see what it is all about, and can format a pure XML doc using xsl fine from their examples, but the problem arises when trying to incorporate it into the existing templates.

    Thanks in advance
    D

  2. #2
    SitePoint Evangelist
    Join Date
    Aug 2007
    Posts
    566
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm not sure I understand your question 100%, but here is my experience with xml+xsl.
    If you want to integrate parts of a web page from an xml source, then you will need to generate an html fragment on the server, get it back and insert it into the html page.

    Basically, an xslt engine can transform any xml file in html (not xhtml, or not w3c valid xhtml to be precise) by using an xsl stylesheet.

    An xsl stylesheet, is nothing more than a template, with some logical elements that will give instructions to the engine about which xml element should be placed where, on which xml elements to do loop and so on...

    I personally designed a couple of sites using this technique, and I like it a lot, but it has it's drawback.
    Now, if you have to go that way, there are some thing you need to know:

    1) not every browser are able to transform xml+xsl natively. To support everyone, you must have an xslt engine on the server to do the transformation and serve html to the client
    2) javascript that use document.write() or div.innerHTML are not going to work. I think this is related to the browsers, but at least, in forefox, they will somply not work.
    3) if you embed javascript or html in the xml, they will need to be escaped to not interfer with the xml markup. And you will need to use CDATA sections to present them correctly.

    If this can make your life easier, I've implemented and mostly automated all of this in a class I released some times ago: http://www.quixml.org
    It requires PHP5 with xmlWriter and the xslt engine to be available for PHP.

    If you want to see xml+xsl in action, go to this site with firefox, and look at the source.
    You will onyl see XML (IE cannot display source xml).
    You will see a reference to an xsl stylesheet at the top, and if you try to go to that url, you will see the stylesheet that is used by the browser to generate the html of that page.

    If you try to access this site with something like netcape 4, the server will detect that the browser is too old to support xslt transformation, and do it itself, to send plain simple html to the browser.

  3. #3
    SitePoint Guru Dashman's Avatar
    Join Date
    Jan 2006
    Location
    Manchester, UK
    Posts
    627
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi ...

    Thanks for your detailed reply, especially the tips ... unfortunately, although I program with PHP myself, the client uses ASP :-(

    Aside from that, I think your link could turn out to be very usefull for future projects.

    Thanks again,

    Dave

  4. #4
    SitePoint Guru Dashman's Avatar
    Join Date
    Jan 2006
    Location
    Manchester, UK
    Posts
    627
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sorry, thought my first response did not post

    Hi ... thanks for the detailed replay, and the tips especially ...

    Unfortunately, the client uses ASP. Aside from that, I thin your tips and link could be very useful to me in the future ... thanks again ..
    Last edited by Dashman; Sep 25, 2008 at 02:41. Reason: Posted twice


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •