-
Notifications
You must be signed in to change notification settings - Fork 7.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
62 additions
and
0 deletions.
There are no files selected for viewing
62 changes: 62 additions & 0 deletions
62
ext/xsl/tests/xsltprocessor_exsl_registerPhpFunctionNs.phpt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
--TEST-- | ||
Overriding an EXSLT builtin | ||
--EXTENSIONS-- | ||
xsl | ||
--SKIPIF-- | ||
<?php | ||
$proc = new xsltprocessor; | ||
if (!$proc->hasExsltSupport()) die('skip EXSLT support not available'); | ||
if (LIBXSLT_VERSION < 10130) die('skip too old libxsl'); | ||
?> | ||
--FILE-- | ||
<?php | ||
|
||
function dummy_year($input) { | ||
var_dump($input[0]->textContent); | ||
return 'dummy value'; | ||
} | ||
|
||
function dummy_exit($input) { | ||
var_dump($input); | ||
exit("dummy exit"); | ||
} | ||
|
||
$xsl = <<<XML | ||
<?xml version="1.0" encoding="ISO-8859-1"?> | ||
<xsl:stylesheet version="1.0" | ||
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" | ||
xmlns:date="http://exslt.org/dates-and-times" | ||
extension-element-prefixes="date"> | ||
<xsl:output method="text"/> | ||
<xsl:template match="date"><xsl:value-of select="date:year(@date)"/></xsl:template> | ||
</xsl:stylesheet> | ||
XML; | ||
|
||
$xml = <<<XML | ||
<?xml version="1.0"?> | ||
<page><date date="2007-12-31"/></page> | ||
XML; | ||
|
||
$xsldoc = new DOMDocument(); | ||
$xsldoc->loadXML($xsl); | ||
|
||
$xmldoc = new DOMDocument(); | ||
$xmldoc->loadXML($xml); | ||
|
||
$proc = new XSLTProcessor(); | ||
$proc->importStylesheet($xsldoc); | ||
|
||
// Should override the builtin function | ||
$proc->registerPHPFunctionNS('http://exslt.org/dates-and-times', 'year', dummy_year(...)); | ||
echo $proc->transformToXML($xmldoc), "\n"; | ||
|
||
// Should not exit | ||
$proc->registerPHPFunctionNS('http://www.w3.org/1999/XSL/Transform', 'value-of', dummy_exit(...)); | ||
echo $proc->transformToXML($xmldoc), "\n"; | ||
|
||
?> | ||
--EXPECT-- | ||
string(10) "2007-12-31" | ||
dummy value | ||
string(10) "2007-12-31" | ||
dummy value |