note 30921 deleted from function.xslt-process by sobak

From: Date: Tue, 22 Nov 2016 03:33:31 +0000
Subject: note 30921 deleted from function.xslt-process by sobak
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-207358@lists.php.net to get a copy of this message
Note Submitter: ohlesbeauxjours at yahoo dot fr ---- 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);

« previous php.notes (#207358) next »