|XSLT2.0 in PHP|
| 2:50 am on Sep 20, 2007 (gmt 0)|
XSLT2.0 has one beautiful new feature - regex expression patterns - that will let me accomplish what I need in about 10 lines of code. I've already tried it using a SAXON processor (using oXygen/) -- and it's wonderful. The alternative in XSLT1.0 is probably going to require a few thousand lines of code garbage + lots of pain and suffering.
according to [php.net...] XSLT2.0 is not supported in PHP. I have 2 questions:
1) what's up with that?
2) is there a workaround/hack/plugin/extension for *getting* PHP to do XSLT2.0 somehow?
| 5:17 am on Sep 21, 2007 (gmt 0)|
I'm confused by your question ...
This extension uses libxslt which can be found at » [xmlsoft.org...] libxslt version 1.1.0 or greater is required.
| 2:38 pm on Sep 21, 2007 (gmt 0)|
Thanks coop - I'll elaborate:
Right now, PHP + libxslt runs XSLT1.0, the basic 1999 flavour of XSLT which includes all the basic <xsl:for-each> and <xsl:template> and <xsl:value-of> bits, along with XPATH1.0 which allows methods like "contains(str,str)".
Michael Kay recommended XSLT2 to the W3C in January this year (http://www.w3.org/TR/xslt20/), with a fleet of powerful new features, like <xsl:analyze-string> and <xsl:matching-substring>. XSLT2 uses XPATH2 (http://www.w3.org/TR/xpath20/), another upgrade including new features -- for instance, expressions which match strings captured by regex, "regex-group($group-number)". XSLT2 also has some awesome new date formatting options.
There is only one known XSLT2 processor called SAXON (http://saxon.sourceforge.net/), built by Michael Kay, which was released for the Java and .NET platforms.
Other XSLT processors, including Sablotron, Xalan and MSXML, have not yet adopted XSLT2.
I think Mr. Kay will forgive me quoting from our personal correspondence on this subject: "implementation [for PHP] does not exist because no-one has written one". He continues, "The usual workaround I recommend is to implement XSLT 2.0 transformation as a (Java-based or .NET-based) REST web service, and for the PHP application to submit transformation requests to that web service by means of HTTP requests. An alternative is to use a PHP-Java bridge"
(mods: I submit to your discretion regarding quoting email in a post, see WebmasterWorld TOS)
Michael Kay manages an email-based discussion group called MulberryTech, a good resource for learning XSLT techniques (both 1 and 2). (http://www.mulberrytech.com/xsl/xsl-list/)
In my particular situation, I got around the XSLT1.0 limitations by parsing the XML with PHP and doing some "preg_replace()" string manipulation to it before passing the result into my XSLT transformation. It's a compromise... I get the output I want, even though to do it I had to molest the XML. With XSLT2, I could leave the XML intact and pass it directly through XSLT to get my desired output.
So - when will PHP get XSLT2 functionality? Not soon enough, that's when.
| 1:23 am on Sep 23, 2007 (gmt 0)|
|So - when will PHP get XSLT2 functionality? |
Open source software comes into existence only after a programmer unselfishly donates the effort. If you don't have the time to do so, and nobody else has yet, then you are correct -- you will have to wait. And from your response I take it you don't have the time to code it yourself.
I've been here, my friend. And often times it comes in the middle of a project with a deadline. Pressure. That's when you have to make a decision, is it going to cost me as much time to contribute to the open source effort as it would to design a workaround? In this case you already have a workaround. Other times you may find that you are better off writing the code and contributing to the effort.
It's one of those situations where you go "ugh, I don't want to be in this position! Do I write a hack or do I hammer out the complete solution and contribute to the open source movement?" I've written my fair share of workarounds, and I've contributed my fair share of open source code. The first leaves you feeling like you threw a hack in place just to get the job done. But guess what? The job gets done, and nobody is any wiser that there is a hack in place except you. The process steps still work, just like you expect them too, it's just not your "ideal" solution. "Hack" is the word you'll use to describe the solution, but that is the only place it gets ugly, in the way you describe it! It still works! And it will continue to work! Don't sweat it, but if it is going to keep you up nights ... hehe, write the code and contribute. And rest easy.
| 1:49 pm on Sep 24, 2007 (gmt 0)|
It's embarassing to admit in public, but I've contributed almost nothing to open source software. I'm so busy using it that I can't spare any time to build it. At some point the imbalance will send me into paroxyms of guilt.
I've offered thousands of source code snippets to the world (via forums, posts, comments, debugging sessions, etc) to solve specific problems, but that's where my benevolence endeth.
Isn't it mighty of me to whine about features that are missing from PHP, asking a huge open source project to support technology that has only existed (publicly) for less than a year? As a lazy freeloader shouting to a crowd, my complaint sounds pretty shallow.
Yet there are many people using XSLT2 in .NET and Java who would love to see this technology ported into PHP. I hope it's only a matter of time (months? years?) before the same motivated crowd who created xsltlib will eventually develop an XSLT2 engine.
Yet while today I'm complaining about XSLT2, tomorrow I might be looking for something else. I must accept that when it comes down to it, anything on the web can be built out of plain old files and gfx and HTML. The rest of the trappings (CSS,PHP,AJAX,SQL,etc) just make the job easier. When I am capable of achieving a result using a simple preg_replace on the XML, I shouldn't get huffy about not being able to do the same thing with a fancier tool.
Taking a Buddhist approach to this:
Dukkha - life is full of suffering.
Samudaya - suffering is caused by desire
Nirodha - to eliminate suffering, eliminate desire
Today's word of the day is "acceptance"