note 30921 added to function.xslt-process

From: Date: Thu, 03 Apr 2003 12:14:22 +0000
Subject: note 30921 added to function.xslt-process
Groups: php.notes 
Request: Send a blank email to php-notes+get-46161@lists.php.net to get a copy of this message
The XSLT document() function can only open local files. But thanks to the Sablotron handlers, you can easely write an http-handler (or even ftp- !!). This sample opens a particular XHTML page on the W3C, and will parse it to get the TITLE tag content. The interesting point, here, is that the url to open (www.w3.org/TR/REC-xml) is defined... inside an XML document :) // XML content : $xml='<?xml version="1.0"?> <page url="www.w3.org/TR/REC-xml">W3C Recommendation page</page>'; // XSL content : $xsl='<?xml version="1.0"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="html" encoding="ISO-8859-1" indent="no" omit-xml-declaration="yes" standalone="yes" media-type="text/html"/> <xsl:template match="/"> The title is : <xsl:value-of select="document(concat(\'http:\',page/@url))/html/head/title"/> </xsl:template> </xsl:stylesheet>'; // TRANSFORMATION : function handGetAll($processor,$scheme,$rest) { $rest=substr($rest,1); switch($scheme) { case 'http': $file = fopen("http://".$rest,"r"); while(!feof($file)) $c .= fgets($file, 1024); fclose($file); return $c; break; } } $xh = xslt_create(); xslt_set_scheme_handlers($xh,array("get_all" => "handGetAll")); echo xslt_process($xh,'arg:/_xml', 'arg:/_xsl',NULL,array("/_xml"=>$xml,"/_xsl"=>$xsl)); xslt_free($xh); -- http://www.php.net/manual/en/function.xslt-process.php http://master.php.net/manage/user-notes.php?action=edit+30921 http://master.php.net/manage/user-notes.php?action=delete+30921 http://master.php.net/manage/user-notes.php?action=reject+30921

« previous php.notes (#46161) next »