SitePoint Sponsor

User Tag List

Results 1 to 25 of 25

Thread: PHP 5 & XSLT

  1. #1
    SitePoint Enthusiast
    Join Date
    Jun 2003
    Location
    Ljubljana, Slovenia
    Posts
    83
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    PHP 5 & XSLT

    what are the new functions .. since XSLT funcs have been removed from PHP 5 ???

    any DOCS available ?


    any help would be appreciated ..

    Bye

    Armando

  2. #2
    SitePoint Enthusiast Morgoroth's Avatar
    Join Date
    May 2003
    Location
    Canada
    Posts
    89
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    xslt functions REMOVED from php5? Ikes.. i thought they were going to be replacing it, not removing it...

    they couldn't they wouldn't... unless theres a better solution?

  3. #3
    SitePoint Zealot sleepeasy's Avatar
    Join Date
    Sep 2003
    Location
    Bristol, UK
    Posts
    145
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    importStylesheet()
    transformToDoc()
    transformToUri()
    transformToXml()
    setParameter()
    getParameter()
    removeParameter() 
    really quick transformation example:

    PHP Code:
    $xmlDoc = new DomDocument();
    $xmlDoc->load('foo.xml');

    $xslt = new XsltProcessor();
    $xslt->importStylesheet('bar.xml');
    // I have no idea what the first parameter is for. And I haven't really bothered to investigate... but passing NULL is fine.
    $xslt->setParameter(NULL, (string) $name, (string) $value);

    $transformation $xslt->transformToXml($xmlDoc); // returns string
    echo $transformation;

    // or

    $transformation $xslt->transformToDoc($xmlDoc); // returns DomDocument object
    echo $transformation->saveXml(); 
    Always open to question or ridicule

  4. #4
    SitePoint Zealot sleepeasy's Avatar
    Join Date
    Sep 2003
    Location
    Bristol, UK
    Posts
    145
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by sleepeasy
    PHP Code:
    // I have no idea what the first parameter is for. 
    // And I haven't really bothered to investigate... but passing NULL is fine.
    $xslt->setParameter(NULL, (string) $name, (string) $value); 
    (For anyone interested) The first parameter specifies the Namespace - but it's not used yet.
    Last edited by sleepeasy; Dec 4, 2003 at 12:44.
    Always open to question or ridicule

  5. #5
    SitePoint Member maximo's Avatar
    Join Date
    Dec 2003
    Location
    Brasilia, Brazil
    Posts
    7
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    So, anyway, what happens with XSLT support in PHP5? I have an enterprise app that is completely built arround XSLT using Sablotron. My scripts generate XML, call the relevant XSL files and rander HTML through XSLT.

    How does that change in PHP5?

  6. #6
    SitePoint Zealot sleepeasy's Avatar
    Join Date
    Sep 2003
    Location
    Bristol, UK
    Posts
    145
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    For what you want to do just use the functions i mentioned in one of the posts in this thread.

    What's cool about XML in PHP5:

    • W3C Compliant
    • EXSLT support*
    • Call any PHP function from within your XSLT stylesheets*
    • XSLT is very fast (in my experience)
    • Support for streams
    • XInclude
    • XSchema, RelaxNG and DTD validation
    • Extensible classes
    • Exceptions
    • Full XML Namespace support
    • SimpleXML
    • SimpleXML <-> DOM Interoperability
    • XPath


    * Only in CVS to my knowledge

    Basically XML in PHP5 is great.
    Always open to question or ridicule

  7. #7
    SitePoint Wizard silver trophy Karl's Avatar
    Join Date
    Jul 1999
    Location
    Derbyshire, UK
    Posts
    4,411
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If you're using Sablotron now, then in PHP5 your app will be much faster when coded to work with the PHP5 XSLT functions as Sablotron is slow compared to the new functions - in fact it's slow compared to the existing DOM XSLT functions in PHP4.
    Karl Austin :: Profile :: KDA Web Services Ltd.
    Business Web Hosting :: Managed Dedicated Hosting
    Call 0800 542 9764 today and ask how we can help your business grow.

  8. #8
    SitePoint Member maximo's Avatar
    Join Date
    Dec 2003
    Location
    Brasilia, Brazil
    Posts
    7
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That's a relief. Sablotron seems to add quite a lot to the processing times. If I just run the script that generates the XML, without calling the XSLT functions from Sablotron, I get like 0.03 seconds processing on a page with 10+ queries (running on a Dual Xeon 3.06 Server with 4 gigs of RAM).... turn XSL processing on, and it goes to 0.3 seconds. Quite a difference eh?
    The dude that invented Object Orientation should have won a Nobel.

  9. #9
    SitePoint Member
    Join Date
    Jan 2004
    Location
    Melbourne, AU
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I get a Fatal error: Class 'XsltProcessor' not found,

    I'm assuming this is because I havn't loaded the XSL functionality. Can you run through a windows/linux php5 xsl installation?

  10. #10
    SitePoint Member
    Join Date
    Jan 2004
    Location
    Melbourne, AU
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    For windows users, simple drop php_xsl.dll into your windows system directory and uncomment the line in php.ini.

    However, I found the code to replicate the above mentioned to be as follows:

    <?
    $xml = new DomDocument;
    $xml->load('article.xml');

    $xsl = new DomDocument;
    $xsl->load('article.xsl');


    $xslt = new XsltProcessor;
    $xslt->importStylesheet($xsl);

    $transformation = $xslt->transformToXml($xml);
    echo $transformation;
    ?>

  11. #11
    SitePoint Member
    Join Date
    Mar 2004
    Location
    Barcelona
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I get the same error but under Linux.
    Any usefull comment would be great!!!

    Quote Originally Posted by aidan
    For windows users, simple drop php_xsl.dll into your windows system directory and uncomment the line in php.ini.

    However, I found the code to replicate the above mentioned to be as follows:

    <?
    $xml = new DomDocument;
    $xml->load('article.xml');

    $xsl = new DomDocument;
    $xsl->load('article.xsl');


    $xslt = new XsltProcessor;
    $xslt->importStylesheet($xsl);

    $transformation = $xslt->transformToXml($xml);
    echo $transformation;
    ?>

  12. #12
    Non-Member
    Join Date
    Jan 2004
    Location
    Planet Earth
    Posts
    1,764
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yet to look at PHP5 myself, though I'm reading with interest, sorry can't help you though

  13. #13
    SitePoint Member
    Join Date
    Mar 2004
    Location
    Barcelona
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Off course, It was my mistake, I had forgotten to install libxslt
    It works!!

  14. #14
    SitePoint Guru worchyld's Avatar
    Join Date
    Jul 2003
    Location
    Newcastle upon Tyne
    Posts
    909
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Is there a way of doing XsltProcessor without resorting to installing php5+ or getting salbotron or whatever. I ask because most hosts haven't moved to php5 yet so I cannot get the XsltProcessor to work unless I use php4+.

    If possible, does anybody know how to get the XsltProcessor thing to work without installing third-party software on php4+?

    Many thanks.

  15. #15
    ********* Victim lastcraft's Avatar
    Join Date
    Apr 2003
    Location
    London
    Posts
    2,423
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Hi...

    I've personally had a real nightmare trying to get libxml2 installed to a sufficient level to keep PHP5 happy (under Mandrake). Seems there are all sorts of unlisted dependencies in the later versions of the libxml RPMs. In particular you need zlib1 of a pretty recent version and libm.so.6 (part of the core) and devel versions to boot.

    I gave up with the dependency hell until someone builds a PHP5 RPM.

    yours, Marcus
    Marcus Baker
    Testing: SimpleTest, Cgreen, Fakemail
    Other: Phemto dependency injector
    Books: PHP in Action, 97 things

  16. #16
    SitePoint Guru worchyld's Avatar
    Join Date
    Jul 2003
    Location
    Newcastle upon Tyne
    Posts
    909
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ah screw it then, I don't understand why they made PHP5 so hard to install and use. If it's not one thing (moving dll's, changing lots of stuff in the ini's) it's another (for example it says in the installation readme to point the extension directory to the folder called extension, except there was never any folder called extension provided).

  17. #17
    SitePoint Enthusiast dodga's Avatar
    Join Date
    Apr 2004
    Location
    Germany
    Posts
    90
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Just had a quick look on this thread, so I don't know if it was already mentioned, but having a quick glance at the PHP manual reveals
    Note: This extension has been removed as of PHP 5 and moved to the PECL repository.
    Note: If you need xslt support with PHP 5 you can use the XSL extension.
    (from http://www.php.net/manual/en/ref.xslt.php)

    The documentation for the XSL stuff in PHP 5 is at http://www.php.net/manual/en/ref.xsl.php

    From that page:
    PHP 5 includes the XSL extension by default and can be enabled by adding the argument --with-xsl[=DIR] to your configure line. DIR is the libxslt installation directory.
    So it should work out-of-the-box

    BTW, I use the Debian packages from dotdeb.org and they work like a charm -- no apache2 support though
    remember my name - you'll scream it later

  18. #18
    SitePoint Guru OfficeOfTheLaw's Avatar
    Join Date
    Apr 2004
    Location
    Quincy
    Posts
    636
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by lastcraft
    Hi...

    I've personally had a real nightmare trying to get libxml2 installed to a sufficient level to keep PHP5 happy (under Mandrake). Seems there are all sorts of unlisted dependencies in the later versions of the libxml RPMs. In particular you need zlib1 of a pretty recent version and libm.so.6 (part of the core) and devel versions to boot.

    I gave up with the dependency hell until someone builds a PHP5 RPM.

    yours, Marcus
    In a debian, it was a simple "apt-get install libxml2"

    but afaik, mandrake's urpmi should do the job too, but I haven't dabbled much in rpm based distros for a year or so.

  19. #19
    SitePoint Wizard Dangermouse's Avatar
    Join Date
    Oct 2003
    Posts
    1,024
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I was playing with the new xsl stuff on windows, looks pretty cool. Ill attatch a zip if you want to see my examples (nothing spectacular).

  20. #20
    SitePoint Guru OfficeOfTheLaw's Avatar
    Join Date
    Apr 2004
    Location
    Quincy
    Posts
    636
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Dangermouse
    I was playing with the new xsl stuff on windows, looks pretty cool. Ill attatch a zip if you want to see my examples (nothing spectacular).

    Actually, I'll post a link to my resume tonight... I made an xhtml/css version, which I'm going to play transforming my HR-XML version of it to the xhtml version.

    Gotta impress prospective employers

  21. #21
    SitePoint Guru thr's Avatar
    Join Date
    Jun 2003
    Location
    Sweden
    Posts
    664
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I didn't have any big problems installning libxml2 och libxslt1 on my Debian 3.0r2 platform. No wierd dependencies, etc.

  22. #22
    SitePoint Guru OfficeOfTheLaw's Avatar
    Join Date
    Apr 2004
    Location
    Quincy
    Posts
    636
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

  23. #23
    SitePoint Enthusiast
    Join Date
    Jun 2005
    Posts
    25
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    guys

    i could not find php_xsl.dll anywhere on my system

    could anyone tell me where do i find it

  24. #24
    SitePoint Enthusiast
    Join Date
    Jun 2004
    Location
    London
    Posts
    66
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Have had no real problems with the gnu/linux ubuntu PHP5 32/64 packages

    http://archive.ubuntu.com/ubuntu/pool/main/p/php5/
    David Stevens, create-inspire
    PHP London, www.phplondon.org

  25. #25
    SitePoint Addict timvw's Avatar
    Join Date
    Jan 2005
    Location
    Belgium
    Posts
    354
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The only issue i discovered with xsl instead of xslt is that the basepath used for <xsl:include etc can't be set anymore.. this may mean you need to use either a filepath (this way, the path is set right) instead of a string with the xsl in or rewrite the xsl so that all locations in <xsl:include are modified...


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •