making XSLT readable - has this been done before?
Published 2007-04-11 13:46:00
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:
Compile parser generator:
Convert the above file to xslt:
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
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("/") {Writing a simple parser generator in D, enabled the generation of the xslt file from this file.
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]");
}
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
Mentioned By:
google.com : april (108 referals)
www.planet-php.net : Planet PHP (26 referals)
xhtml.net : XHTML.net (21 referals)
google.com : december (14 referals)
b.hatena.ne.jp : はてなブックマーク - k1mのブックマーク / xslt (8 referals)
google.com : php rss xslt (7 referals)
google.com : xslt readable (7 referals)
google.com : php xslt (6 referals)
swik.net : making XSLT readable - has this been done before? - SWiK (4 referals)
google.com : php XSLT2 (4 referals)
google.com : jslt xsl (3 referals)
google.com : php convert xsl to html (3 referals)
google.com : toooooo (3 referals)
google.com : xslt if node doesent exist (3 referals)
www.debian.org.hk : Debian HK | Debian @ Hong Kong (2 referals)
google.com : "XSL to php" (2 referals)
google.com : akbk (2 referals)
google.com : convert xsl to php (2 referals)
google.com : feed php variable to xsl (2 referals)
google.com : how much readible php is (2 referals)
google.com : april (108 referals)
www.planet-php.net : Planet PHP (26 referals)
xhtml.net : XHTML.net (21 referals)
google.com : december (14 referals)
b.hatena.ne.jp : はてなブックマーク - k1mのブックマーク / xslt (8 referals)
google.com : php rss xslt (7 referals)
google.com : xslt readable (7 referals)
google.com : php xslt (6 referals)
swik.net : making XSLT readable - has this been done before? - SWiK (4 referals)
google.com : php XSLT2 (4 referals)
google.com : jslt xsl (3 referals)
google.com : php convert xsl to html (3 referals)
google.com : toooooo (3 referals)
google.com : xslt if node doesent exist (3 referals)
www.debian.org.hk : Debian HK | Debian @ Hong Kong (2 referals)
google.com : "XSL to php" (2 referals)
google.com : akbk (2 referals)
google.com : convert xsl to php (2 referals)
google.com : feed php variable to xsl (2 referals)
google.com : how much readible php is (2 referals)
Follow us
-
- Some thoughts on the language server and its usefulness in the roobuilder
- Roo Builder for Gtk4 moving forward
- Clustered Web Applications - Mysql and File replication
- GitLive - Branching - Merging
- PDO_DataObject Released
- PDO_DataObject is under way
- Mass email Marketing and anti-spam - some of the how-to..
- Hydra - Recruitment done right
Blog Latest
-
Twitter - @Roojs