Zend - The PHP Company




XML

Add Code


Dynamically transform XML and XSL with XSLT into Html without the Sablotron extension  

Type: application
Added by: xpc
Entered: 28/05/2002
Last modified: 06/12/2001
Rating: - (fewer than 3 votes)
Views: 10369
Transforms a (local|remote) XML file and its accompanying (local|remote) XSL file into html on the server using either a client output buffering in MSIE only or via a URL HTTP GET include via the W3's XSLT public web service.


<?PHP

/*

What:

Transforms a (local|remote) XML file and its accompanying (local|remote) XSL file into html on the server
using either a client output buffering in MSIE only or
via a URL HTTP GET include via the W3's XSLT public web service.

Credits:

This comes builtin to PHPortal (c) 2002 - Application Builder LGPL (free non-commercial)
(http://dev.4arrow.com) of http://4Arrow.com by Michael Glazer http://coding.4arrow.com

PHPortal has dynamic Content-Type Transformations for over 15 formats
available format types (PHPortal source,xml,rss,vxml,text,excel,word,jpeg,zip,html,xhtml,javascript,swf/flash,css,wml,pdf)

Requires:

Info:

http://www.php.net/manual/en/ref.xslt.php
http://www.w3.org/2001/05/xslt
http://www.gingerall.com/
http://www.zvon.org/HTMLonly/XSLTutorial/Books/Book1/
http://www.w3.org/Style/XSL/

Example:

$args=array(
    xsl    =>    "http://4arrow.com/format/tpl/rss/weblogRSS91.xsl",
    xml    =>    "http://coding.4arrow.com/log/headlines.xpc.rss"

);

    function XSLT($args=''){

        if(strstr($_SERVER["HTTP_USER_AGENT"],"MSIE")){

            $str=xslt_trans_js($args['xsl'],$args['xml']);

            }
                else{

                    $str=xslt_trans_w3($args['xsl'],$args['xml']);
                }

        return $str;

        }//end if
    }

*/

function xslt_trans_js($xsl='',$xml=''){

    
$str='

    <script>

    function transform(str1,str2){
    var xml = new ActiveXObject("Microsoft.XMLDOM");
    var xsl = new ActiveXObject("Microsoft.XMLDOM");
    xml.async = false;
    xsl.async = false;
    xsl.load(str1);
    xml.load(str2);
    var theString = xml.transformNode(xsl);
    document.write (theString);
    }

    transform(''.$xsl.'',''.$xml.'');

    </script>

    '
;

    
ob_start();

    echo 
$str;

    
$contents ob_get_contents();

    
ob_end_clean();

return 
$contents;

}

function 
xslt_trans_w3($xslfile='',$xmlfile=''){

    
$rfile="http://www.w3.org/2000/06/webdata/xslt?xslfile=$xslfile&xmlfile=$xmlfile";

    
$str=include_once($rfile);

return 
$str;

}

?>


Usage Example


See the example


Rate This Script





Search



This Category All Categories