The Artima Developer Community
Sponsored Link

PHP Buzz Forum
making XSLT readable - has this been done before?

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Alan Knowles

Posts: 390
Nickname: alank
Registered: Sep, 2004

Alan Knowles is Freelance Developer, works on PHP extensions and PEAR.
making XSLT readable - has this been done before? Posted: Apr 10, 2007 11:11 PM
Reply to this message Reply

This post originated from an RSS feed registered with PHP Buzz by Alan Knowles.
Original Post: making XSLT readable - has this been done before?
Feed Title: Smoking toooo much PHP
Feed URL: http://www.akbkhome.com/blog.php/RSS.xml
Feed Description: More than just a blog :)
Latest PHP Buzz Posts
Latest PHP Buzz Posts by Alan Knowles
Latest Posts From Smoking toooo much PHP

Advertisement
We where discussing with one of my clients the idea of including dynamic content on their home page, which is currently static HTML, due to extreme load requirements. Normally Php is only reserved for specific parts of the site, and not on the front page.

I had the idea of using XmlHttpRequest, however another member of the team suggested XSLT, and I have to admit, I've never seen that idea before, and the example he showed basically included content from an external file by just adding a simple tag like
<our:include src="mydynamic.html" part="xxx" />
Where the mydynamic.html could use the 404 handler trick that php.net uses. (eg. if the file doesnt exist, it gets generated by the 404 handler, and deleted by a cronjob every 5 minutes etc.)

My only reservation about this is really that XSLT templates are unreadable garbage. Hence if we ever started to get clever with them, they could quickly become unmaintainable.

This however didnt seem to be a problem so much with XSLT but the fact that reading and writing XSLT files is not particulaly simple. Looking at the Basic specification for 1.0, and the example file he had, it seem clear that this file could easily be generated by a simple tool. However I could not find anything after a quick google search that seemed to exist to do this. So I threw together a simple proof of concept.

What if the template looked more like this:
template("/") {
applyTemplates;
}

template("*") {
copy {
applyTemplates("@*|node()");
}
}

template("processing-instruction()") {
copy {
applyTemplates("@*|node()|text");
}
}

// make h1 green

template("html:h1")
{
copy {
attribute("style") <colour:green>
applyTemplates("@*|node()");
}
}

template("our:include")
{
variable("part", "@part");
applyTemplates("document(@src)//*[@id=$part]");
}


Writing a simple parser generator in D, enabled the generation of the xslt file from this file.

Compile parser generator:
dmd xsltgen.d -of/tmp/xsltgen -od/tmp

Convert the above file to xslt:
/tmp/xsltgen inctest.xslts

And magically you have a generated file, and a maintainable version.. - Makes me wonder though, has someone done this already?

the source: xsltgen.d
output from the above example: inctest.xslt

Read: making XSLT readable - has this been done before?

Topic: MySpace Sucks as a Social Tool. Previous Topic   Next Topic Topic: Working example of Microformats as an API

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use