views:

271

answers:

1

EDIT: What I mean is displaying the XML data through HTML, not trying to get HTML into XML.

Is there a simple way to load content from XML into HTML? To give you an idea, here is my DTD for the XML files:

  <!DOCTYPE bookreport [
    <!ELEMENT page (title,author,image?,section+)>
      <!ELEMENT title (#PCDATA)>
      <!ELEMENT author (#PCDATA)>
      <!ELEMENT image (path,side,alternate?)>
        <!ATTLIST image type CDATA #REQUIRED>
        <!ATTLIST image width CDATA #REQUIRED>
        <!ATTLIST image height CDATA #REQUIRED>
        <!ATTLIST image bookcover (yes) "no">
        <!ELEMENT path (#CDATA)>
        <!ELEMENT side (#CDATA)>
        <!ELEMENT alternate (#PCDATA)>
      <!ELEMENT section (name,image?,paragraph*,subsection*)>
        <!ELEMENT name (#PCDATA)>
        <!ELEMENT paragraph (#PCDATA)>
          <!ELEMENT emphasis (#PCDATA)>
        <!ELEMENT subsection (name,paragraph+,image?)>
  ]>

So as you can see, it is separated into sections and subsections. The only actual visual markup in the XML in the <emphasis> tag, which I wan't to convert to italics. I've also made a CSS layout that I like, two column, partly fluid and stays centered. What I want is for it to have links in the navigation bar to each #section.

I would really like doing it like this because it separates the data from the markup, which is also separated from the appearance (CSS). Is it possible to do it without server-side coding (JavaScript I'm guessing) ? If not, how can I do it in PHP? Even if it's better with PHP, I would also like to know how (if possible) to do it with JavaScript, so that I could use that when PHP is not available. This is not for anything important.

+1  A: 

You can do an XSLT transformation of the XML data on the client with Javascript to obtain your HTML;

This should get you started

Gurdas Nijor
This looks like what I want, I'll try it out.
Mk12
Thanks! Just took a few hours and I'm very happy with the result. Identical to plain html version in both content and speed (noticeable speed).
Mk12
Should I use XSLT 1.0 or 2.0?
Mk12