
November 21st, 2002, 01:10 PM
|
|
Junior Member
|
|
Join Date: Apr 2001
Posts: 15
Time spent in forums: < 1 sec
Reputation Power: 0
|
|
|
Sablotron, PHP, and PI's
Hello,
I've been having some problems getting the xslt_set_sax_handlers() function to work w/ processing instructions.
My current problem is that the $target argument passed into xslt_set_sax_handlers function contains nothing and the $data arg contains the pi target, in this case the string 'php'.
As you can see this is a problem, has anyone experienced this? What's the work around. I really need to be able to use pi's in my xsl docs.
here's the code:
pitest.cgi:
PHP Code:
#!/usr/bin/php4
<?php
// Allocate a new XSLT processor
$xh = xslt_create();
xslt_set_sax_handlers($xh, array('pi'=>'process'));
/* Processing Instruction handler */
function process($parser, $target, $data) {
if($target == 'php') {
// eval() some code here
}
}
// Process the document, returning the result into the $result variable
$result = xslt_process($xh, "pi.xml", "test.xsl", NULL, array(), array());
if ($result) {
print $result;
} else {
print "Sorry, sample.xml could not be transformed by sample.xsl into";
print " the \$result variable the reason is that " . xslt_error($xh) .
print " and the error code is " . xslt_errno($xh);
}
xslt_free($xh);
?>
pi.xml:
<?xml version="1.0" encoding="UTF-8"?>
<!--<!DOCTYPE doc SYSTEM "dtd/what_press_also.dtd">-->
<doc segment="" product="">
<test>TEST NODE</test>
<title>
blah
<?php print "TEST";?>
</title>
<topnav>
<?php?>
</topnav>
<leftnav>
<?php?>
</leftnav>
<body>
<?php?>
</body>
<contact>
<?php?>
</contact>
<whatshot>
<ids>1 18 33</ids>
<?php?>
</whatshot>
<seealso>
<ids>22 57 90</ids>
<?php?>
</seealso>
<footer>
<?php?>
</footer>
</doc>
test.xsl:
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:output method="html" />
<xsl:template match="/">
<xsl:apply-templates select="doc/title/processing-instruction()"/>
</xsl:template>
<xsl:template match="processing-instruction()">
<xsl:processing-instruction name="php"><xsl:value-of select="."/></xsl:processing-instruction>
</xsl:template>
</xsl:stylesheet>
Last edited by MrHyde : November 21st, 2002 at 01:31 PM.
|