xslt011.phpt 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. --TEST--
  2. Test 11: php:function Support
  3. --EXTENSIONS--
  4. xsl
  5. --FILE--
  6. <?php
  7. print "Test 11: php:function Support\n";
  8. Class foo {
  9. function __construct() {}
  10. function __toString() { return "not a DomNode object";}
  11. }
  12. $dom = new domDocument();
  13. $dom->load(__DIR__."/xslt011.xsl");
  14. $proc = new xsltprocessor;
  15. $xsl = $proc->importStylesheet($dom);
  16. $xml = new DomDocument();
  17. $xml->load(__DIR__."/xslt011.xml");
  18. $proc->registerPHPFunctions();
  19. print $proc->transformToXml($xml);
  20. function foobar($id, $secondArg = "" ) {
  21. if (is_array($id)) {
  22. return $id[0]->value . " - " . $secondArg;
  23. } else {
  24. return $id . " - " . $secondArg;
  25. }
  26. }
  27. function nodeSet($id = null) {
  28. if ($id and is_array($id)) {
  29. return $id[0];
  30. } else {
  31. $dom = new domdocument;
  32. $dom->loadXML("<root>this is from an external DomDocument</root>");
  33. return $dom->documentElement;
  34. }
  35. }
  36. function nonDomNode() {
  37. return new foo();
  38. }
  39. class aClass {
  40. static function aStaticFunction($id) {
  41. return $id;
  42. }
  43. }
  44. ?>
  45. --EXPECTF--
  46. Test 11: php:function Support
  47. Warning: XSLTProcessor::transformToXml(): A PHP Object cannot be converted to a XPath-string in %s on line 16
  48. <?xml version="1.0"?>
  49. foobar - secondArg
  50. foobar -
  51. this is from an external DomDocument
  52. from the Input Document
  53. static