views:

85

answers:

4

I have a long document in XML from which I need to produce static HTML pages (for distribution via CD). I know (to varying degrees) JavaScript, PHP and Python. The current options I've considered are listed here:

  • I'm not ruling out JavaScript, so one option would be to use ajax to dynamically load the XML content into HTML pages. Edit: I'd use jQuery for this option.

  • Learn some basic XSLT and produce HTML to the correct spec this way.

  • Produce the site with PHP (for example) and then generate a static site.

  • Write a script (in Python for example) to convert the XML into HTML. This is similar to the XSLT option but without having to learn XSLT.

Useful information:

  • The XML will likely change at some point, so I'd like to be able to easily regenerate the site.

  • I'll have to produce some kind of menu for jumping around the document (so I'll need to produce some kind of index of the content).

I'd like to know if anyone has any better ideas that I haven't thought of. If not, I'd like you to tell me which of my options seems the most sensible. I think I know what I'm going to do, but I'd like a second opinion. Thanks.

+1  A: 

I would go with the PHP option. The reason being is that when the XML changes your site content "should" automatically change without you having to touch your PHP code.

Creating a Python script to generate lots of static pages just seems like a bad idea to me and with javascript you will have your cross-browser headaches (unless you are using a framework maybe).

Use the server side languages for these kind of tasks, it is what they were made for.

Andre
The thing is, it's being distributed on CD, so I'll still have to regenerate the static pages. Also, I will be using jQuery if I go the JS route.
Skilldrick
Is the site distributed buy CD? In other words, will people run this site from the CD-ROM?
Andre
@Andre - Yes...
Skilldrick
In that case, PHP and server side languages are out. Best way forward will probably be Python IMHO, unless you know XSLT very well.
Andre
@Andre - I know you can't run PHP from a CD! That's why I was going to generate a static site from the dynamic PHP site.
Skilldrick
+2  A: 

I would go with the XSLT option, controlled via parameters to generate different pages from the same XML source if needed. It's really the tool made for XML transformations.

Lucero
The only reason I'm not sure about XSLT is because it's a language I've never used before. I'm happy to learn though.
Skilldrick
If you've done some functional/declarative programming before, I think that you'll quickly feel at home with XSLT.
Lucero
A: 

Go with what you are most comfortable with.

If it's straightforward you could use (for example) php to generate a page and then use a command line script (in python or php) to create cached files for you.

zaf
+2  A: 

I think XSLT is by far the easiest and best method -- even taking into account having to learn xslt.

There are several styles of xslt programming, but the easiest is "push processing" , where you write several templates that describe how your xml input is to be transformed into html output. Then you write a root template that outputs the basic html wrapper and calls the other templates. The root template is the easy one:

<xsl:template match="/" > <!-- "/" matches the document root -->
  <html>  <!-- whatever is not in xsl: namespace is template output -->
  <head><title>...</title></head>
  <body>
  <xsl:apply-templates />  <!-- this searches for and calls additional template matches --> 
  </body>
  </html>
</xsl:template>  
Steven D. Majewski
Thanks Steven (and Lucero). I think I'll go with XSLT, and I'll report back when I'm done! If it all goes badly I reserve the right to withdraw my accepted answer :)
Skilldrick