note 61479 added to ref.xslt
| From: | gabriela-tbumptdo-tnet at osu1 dot php dot net | Date: | Sat, 04 Feb 2006 22:50:48 +0000 |
| Subject: | note 61479 added to ref.xslt | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-103007@lists.php.net to get a copy of this message | ||
If you need to transform an XML document that specifies the URL of its own prefered stylesheet
(using the processing instruction <?xml-stylesheet href="xyz.xsl"?>, you can start
by parsing the XML data to retrieve that URL, and then call the xslt_process function using the
specified stylesheet :
<?php
/* A small class for stylesheet URL extraction from an XML */
class XMLStylesheet
{
var $hParser;
var $xml;
var $stylesheet;
function XMLStylesheet($filename)
{
$this->hParser = xml_parser_create();
xml_set_object($this->hParser, $this);
xml_set_processing_instruction_handler($this->hParser, 'fnProcessingInstruction');
$this->xml = file_get_contents($filename);
xml_parse($this->hParser, $this->xml, true);
xml_parser_free($this->hParser);
}
function getStylesheet()
{
return $this->stylesheet;
}
function fnProcessingInstruction($hParser, $target, $data)
{
if($target == 'xml-stylesheet')
{
ereg('href="([^"]+)"', $data, $regs);
$this->stylesheet = $regs[1];
}
}
}
/* Now, instanciate an object of this class, given the filename of our XML data */
$xml = new XMLStylesheet('my_data.xml');
/* And finally, retrieve the URL of the stylesheet specified in the XML data. */
$xsl_url = $xml->getStylesheet());
/* Now you can xslt_process as usual. */
?>
----
Server IP: 195.221.21.36
Probable Submitter: 81.66.150.35
----
Manual Page -- http://www.php.net/manual/en/ref.xslt.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+61479
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+61479&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+61479&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+61479&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+61479&report=yes&reason=useless
Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+61479&report=yes&reason=non-english
Delete: already in docs -- http://master.php.net/manage/user-notes.php?action=delete+61479&report=yes&reason=already+in+docs
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+61479&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+61479&report=yes
Search -- http://master.php.net/manage/user-notes.php