In my last article I covered
the use of the expat functions available to PHP for parsing XML documents using
the SAX method. The sample code was a class that read the XML document and generated
the HTML to present the data in a nice table. This example was far from perfect
due to the fact that the presentation of the data was not separate from the
class code that had to parse the XML document. This meant that a slight modification
to the HTML generated by the class could break the actual parsing functionality
of the class.
This is not the ideal way of doing things in a production environment, hence
the purpose of this article in explaining how to parse XML documents using XSLT
(eXtensible Stylesheet Language Transformations). XSLT is a language for transforming
XML documents into other XML documents or HTML documents. I will not discuss
XML, XSL or XSLT syntax in this article, for a good introduction to these please
refer to the links at the end of this article.The focus of this article is on
how to transform XML documents with XSLT using the Sablotron XSLT processor.
Sablotron is the result of a project to develop a fast, reliable, compact and
portable XSLT processor conforming to the W3C specification. It currently supports
Linux, Windows NT and, beginning with version 0.42, Solaris. It requires the
expat XML Parser. In addition to these pieces of software the PHP4 sablotron
extension wrapper is required to build an extension module that you can load
with the PHP4 parser to give you access to the Sablotron API. This may sound
a bit complex but it's really not and the result is well worth the power that
these functions will provide you with. Some links to instructions on how to
do all this are provided at the end of the article.
To demonstrate the use of these functions I have written an XSLT class that
takes XML and XSL wether it be in the format of a file, a URL or a String and
performs the transform. I use this class to to read an XML document from the
web (the Slashdot news!) and transform it into an HTML page using an XSLT document
on the local file system.
I'll do my best to explain how I've done this and welcome questions in the followup
section, so here goes nothing ! ...
| Comments: |
| syntax-error in sablot 1.0 but not in 0,97 | Michael | 02/16/05 07:29 |
| undefined function: xslt_create_processor() | david | 11/12/04 18:49 |
| RE: XML Fatal error: unknown encoding | Wajee T. | 04/08/04 04:59 |
| RE: Call to undefined function: xslt_create() | Protorium | 02/27/04 12:41 |
| the doc reader class is WRong !!!! | nowhere | 01/20/04 18:50 |
| RE: Working publishing platform XML/XSL | Justin Grant | 07/22/03 23:11 |
| XSL precompiling | Jakob Schwendner | 04/08/03 05:22 |
| RE: official XSLT Support in PHP | yohm | 03/31/03 08:40 |
| Working publishing platform XML/XSL | Alexandru COSTIN | 03/14/03 18:40 |
| working application with xslt | Ilya | 02/20/03 00:17 |
| RE: How can I use gb2312 diretorily in xsl | davidliu | 09/25/02 00:22 |
| How can I use gb2312 diretorily in xsl | davidliu | 09/17/02 23:14 |
| RE: Call to undefined function: xslt_create() | Alexander Lang | 09/05/02 11:43 |
| XSL function for validation | Sathya | 08/20/02 03:04 |
| extension library xsl | Rajeev | 08/16/02 12:22 |
| php_sablot.dll with encoding support | yanhl | 07/27/02 19:07 |
| parsing values from php to xsl | christian Sorensen | 07/23/02 05:15 |
| Subject: Error starting the sample script | Z.Klindzic | 07/11/02 17:25 |
| Error starting the sample script | WoHu | 06/24/02 16:10 |
| Passing a variable or parameter to xsl | Niket Trivedi | 06/20/02 16:05 |
| Passing a param to an xsl file from xsl | Marine | 06/20/02 09:56 |
| official XSLT Support in PHP | Stefan Reier | 06/17/02 09:18 |
| Php & Sablotron 0.9 encoding UTF-16 | sylvain | 06/14/02 06:09 |
| RE: can sablotron show spanish characters | José Zorrilla | 06/10/02 19:47 |
| RE: undefined symbol: JS_PropertyStub | Adam | 05/28/02 15:07 |
| RE: Passing a variable to an xsl file | ala | 05/28/02 05:31 |
| Passing a variable to an xsl file | Desaraju | 05/03/02 16:30 |
| can sablotron show spanish characters | Ernesto moratal | 04/16/02 13:15 |
| xml doument | aaa | 03/24/02 16:16 |
| Installing Sabltron on Win 2000 | martin | 03/20/02 04:23 |
| undefined symbol: JS_PropertyStub | Oliver Bott | 03/14/02 03:14 |
| call to undefined function JS_PropertyStub | Oliver Bott | 03/14/02 03:09 |
| Sablotron | Chris Moore | 02/28/02 12:26 |
| XML Fatal error: unknown encoding | chicky | 02/27/02 02:10 |
| XML Fatal error: unknown encoding | chicky | 02/27/02 01:09 |
| RE: Call to undefined function: xslt_create() | TaQ | 01/29/02 12:03 |
| Call to undefined function: xslt_create() | Bart | 01/03/02 07:52 |
| RE: expat/sablotron install problems | Yasela Udawatte | 12/26/01 23:50 |
| Concate XML Object | Santhosh | 12/22/01 00:02 |
| RE: accentuation problems | skysignature | 12/08/01 00:44 |
| accentuation problems | Gustavo | 10/29/01 15:52 |
| LD_LIBRARY_PATH | Matt Pritchard | 10/26/01 13:03 |
| transformation an XML file | jayakumar D | 10/22/01 04:17 |
| XSL error for output comment generation? | Xavier Outhier | 10/08/01 06:19 |
| xslt-wml/sablotron | bernd | 09/28/01 07:01 |
| Modified XSLTransformer class for PHP4>=4.0.3 | Sandeep Khanna | 09/20/01 00:46 |
| RE: Sablotron Apache1.3.12+PHP4.0.5+Win98 | Boris | 09/19/01 16:04 |
| PHP-Versions, Win2k & Sablotron | Boris | 09/19/01 15:55 |
| RE: include() problem | Jens Schriver | 09/14/01 11:43 |
| Apache configuration | Aleksei | 08/28/01 05:24 |
| RE: FYI: German 'Umlaute' with Sablotron | Salvatore | 08/28/01 02:15 |
| PHP Sablotron extension | Aleksei | 08/27/01 22:08 |
| RE: xslt_process() dies, not returns false | chregu | 08/24/01 00:42 |
| include() problem | chris | 08/02/01 10:34 |
| xml file | Joris Kluivers | 07/18/01 09:48 |
| access to XSL file | jan janssen | 07/17/01 02:55 |
| Problems with 'not valid' HTML in XSL | Alexey AK | 07/06/01 04:16 |
| Sablotron & bad XML/XSL | Lehel | 07/05/01 02:26 |
| RE: xslt_process() dies, not returns false | Alexandre Damiron | 07/04/01 05:26 |
| RE: xslt_process() dies, not returns false | Roberto Shintani | 06/20/01 13:54 |
| RE: sablotron + multiple XSL ? | lsr | 06/05/01 09:35 |
| RE: What about SQL->XML | patbeau | 06/01/01 11:03 |
| XSL with phpXML class? | Tom | 05/20/01 10:34 |
| RE: sablotron + multiple XSL ? | Martynas Majeris | 05/20/01 00:37 |
| sablotron + multiple XSL ? | nono | 05/10/01 08:01 |
| Modified version in Code Library | Melvyn Sopacua | 05/05/01 10:17 |
| RE: undefined function | radhak | 05/02/01 22:38 |
| RE: --------------- COMPLETE STEPS FOR SABLOTRON | Belka | 05/02/01 08:48 |
| undefined function (Transforming | radhak | 05/02/01 03:50 |
| RE: expat/sablotron install problems | Melvyn Sopacua | 04/30/01 16:27 |
| RE: How fast does it go mister? | Jens Schriver | 04/27/01 12:29 |
| RE: XSLT without Sablotron? | Jens Schriver | 04/27/01 12:28 |
| RE: Installation problem (yeah, again) | E.deWolff | 04/26/01 08:38 |
| expat/sablotron install problems | Lehel | 04/24/01 08:50 |
| RE: Installation problem (yeah, again) | Jesper | 04/24/01 04:52 |
| RE: Dinamic XML generation??? | INSTALLING SABLOTRON ON LINUX RH7 | 04/20/01 06:42 |
| XSLT without Sablotron? | Thomas | 04/20/01 05:02 |
| RE: Dinamic XML generation??? | Bryan Brunton | 04/19/01 17:09 |
| Installation problem (yeah, again) | E.deWolff | 04/12/01 12:09 |
| error in xslt | Nicolas | 04/12/01 04:54 |
| RE: Dinamic XML generation??? | Aki Sasaki | 04/04/01 20:55 |
| --------------- COMPLETE STEPS FOR SABLOTRON | Shashank Tripathi | 04/02/01 03:33 |
| dinamic xsl ??? | Emanuele | 03/28/01 02:17 |
| RE: sablotron under windows | quang | 03/13/01 11:11 |
| RE: How fast does it go mister? | Idan Sofer | 03/06/01 17:31 |
| RE: xslt_process() dies, not returns false | Eric Roth | 03/02/01 20:35 |
| RE: Instalation | Gil | 03/01/01 23:55 |
| RE: what W3C XSLT version does Sablotron supports | daniele | 02/28/01 14:05 |
| Updated version of class | Sander Westland | 02/28/01 12:21 |
| PHPLIB, XSLT, and this Article | Bryan Brunton | 02/27/01 16:01 |
| xslt_process() dies, not returns false | Sergey Kanareykin | 02/27/01 14:14 |
| RE: php_sablot.dll | Ola Strandberg | 02/26/01 02:25 |
| why not libxslt (xslt parts of libxml)? | olivier | 02/22/01 05:14 |
| what W3C XSLT version does Sablotron supports | Patricia DiBenedetto | 02/20/01 12:28 |
| RE: php_sablot.dll | Matthew Peltzer | 02/18/01 17:09 |
| php_sablot.dll | Matthew Peltzer | 02/17/01 21:42 |
| Sablotron XSLT_ERROR | George | 02/13/01 23:02 |
| HTML tags in XML document | Peter Blum | 02/11/01 10:10 |
| Dinamic XML generation??? | Daniele | 02/09/01 02:17 |
| Transform XML dinamically generated? | Daniele | 02/09/01 01:26 |
| RE: sablotron under windows | Danny Appaiah | 02/06/01 04:26 |
| Sablotron Apache1.3.12+PHP4.0.5+Win98 | Danny Appaiah | 02/06/01 03:23 |
| RE: HREFs embedded in XML | beek | 01/30/01 13:59 |
| RE: Installing an XSL parser | sto | 01/30/01 01:04 |
| RE: sablotron under windows | sto | 01/30/01 01:00 |
| Simple/Exact Steps for XSLT in WIN32 | wasti | 01/25/01 13:07 |
| php_sablot | n000b | 01/25/01 01:55 |
| RE: sablotron under windows | Don Buchanan | 01/25/01 00:44 |
| RE: Apache on W2000... & Sablotron future | Taco | 01/24/01 11:34 |
| RE: Apache on W2000 php4.04 (rtfm) | Peter | 01/24/01 07:32 |
| RE: Apache on W2000 php4.04 (rtfm) | Taco | 01/23/01 12:46 |
| RE: HREFs embedded in XML | Nam Xuan | 01/17/01 03:55 |
| encoding problem | Dmitry Rud | 01/15/01 05:12 |
| passing parameters - please help | Jens | 01/15/01 04:08 |
| RE: How can I use utf-16 or euc-kr encoding? | Al Lin | 01/15/01 00:08 |
| Apache on W2000 php4.04 | jan janssen | 01/11/01 06:20 |
| Problems with sablotron... | Andrew Nappin | 01/10/01 06:45 |
| HREFs embedded in XML | Charles Dostale | 12/29/00 12:39 |
| RE: Getting Sablotron with W32 PHP | Tim K | 12/08/00 15:02 |
| Installing an XSL parser | Jay | 12/07/00 18:36 |
| Using output buffering and XSLT transform | Nam Xuan | 12/06/00 22:30 |
| RE: FYI: German 'Umlaute' with Sablotron | Justin Grant | 12/06/00 00:45 |
| FYI: German 'Umlaute' with Sablotron | Axel Tietje | 12/01/00 08:00 |
| Getting Sablotron with W32 PHP | Ronald TAO | 11/21/00 11:56 |
| How can I use utf-16 or euc-kr encoding? | Jaewook Ahn | 11/18/00 10:21 |
| RE: modification to allow passing parameters | Greg | 11/15/00 14:39 |
| modification to allow passing parameters | dietrich | 11/09/00 15:29 |
| New API in PHP 4.0.3pl1 | Nam Xuan | 11/09/00 02:50 |
| undefined function | siva | 11/09/00 00:54 |
| RE: Getting Sablotron Working | Urs Gehrig | 11/08/00 18:26 |
| setting xml and xsl from strings | rowan | 11/08/00 17:45 |
| RE: Error on shutdown | rowan | 11/08/00 17:41 |
| GEEZ the install is conveluted. | Greg | 11/08/00 16:17 |
| DLLs files for windows | Bogdan | 11/08/00 10:47 |
| Forgot to mention my config statement.... | Greg | 11/07/00 12:12 |
| Getting Sablotron Working | Greg | 11/07/00 11:48 |
| How fast does it go mister? | Alan Garfield | 11/07/00 05:49 |
| RE: What about SQL->XML | Terence | 11/06/00 19:59 |
| RE: Instalation | Mika | 11/04/00 22:25 |
| RE: Output Buffering + Sablot Ext. | Walter Jerusalinsky | 11/03/00 21:27 |
| What about SQL->XML | seth banks | 11/03/00 14:52 |
| RE: Output Buffering + Sablot Ext. | Urs Gehrig | 11/03/00 06:58 |
| Error on shutdown | Michael Payne | 11/01/00 02:08 |
| Output Buffering + Sablot Ext. | Walter Jerusalinsky | 10/31/00 20:49 |
| RE: Instalation | Vincent Vollers | 10/31/00 09:00 |
| RE: Instalation | Oliver Kurz | 10/30/00 04:06 |
| more columns like this please! | Terence | 10/29/00 19:12 |
| RE: Instalation (same here) | M. Refky | 10/29/00 10:33 |
| RE: Instalation | M. Refky | 10/29/00 10:01 |
| RE: Instalation (same here) | Vincent Vollers | 10/28/00 11:31 |
| RE: sablotron under windows [DISREGARD PREV] | Walter | 10/27/00 18:29 |
| RE: sablotron under windows - problem | Walter | 10/27/00 18:18 |
| Instalation | Luis Argerich | 10/27/00 09:47 |
| RE: Different API --- PHP 4.0.3 (XSL Parms) | Jens Wabnitz | 10/27/00 03:09 |
| RE: How do you compile this ? | dietrich | 10/27/00 01:27 |
| RE: Different API --- PHP 4.0.3 (XSL Parms) | Justin Grant | 10/26/00 18:47 |
| RE: Different API --- PHP 4.0.3 | Jens Wabnitz | 10/26/00 13:41 |
| RE: Different API --- PHP 4.0.3 | Justin Grant | 10/26/00 12:32 |
| trying to load sablotron | w00g | 10/26/00 05:31 |
| How do you compile this ? | Oliver Kurz | 10/26/00 05:05 |
| Different API --- PHP 4.0.3 | Mark Melvin | 10/25/00 18:40 |
| RE: Bug in XSL File? | Justin Grant | 10/25/00 15:43 |
| sablotron under windows | Pierre Kessler | 10/25/00 14:45 |
| Bug in XSL File? | Pat O'Neill | 10/25/00 10:07 |
|
If you are looking for help, please post on the appropriate forum here. Your questions will be answered much more quickly.
|