XslRecurse.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <?php
  2. Lib::loadClass('RouteBase');
  3. class Route_Test_XslRecurse extends RouteBase {
  4. function defaultAction() {
  5. UI::layout( [ $this, 'defaultView' ], [ 'showMenu' => false ] );
  6. }
  7. function defaultView() {
  8. Lib::loadXslFunction('testFetchWfs');
  9. Lib::loadXslFunction('testHtmlContent');
  10. $xml = "
  11. <root>
  12. <item typeName=\"default_db:TEST_PERMS\">
  13. <featureId>TEST_PERMS.1</featureId>
  14. </item>
  15. <item typeName=\"default_db:TEST_PERMS\">
  16. <featureId>TEST_PERMS.99999</featureId>
  17. </item>
  18. <item typeName=\"default_db__x3A__TEST_PERMS:TestPermsAnt\">
  19. <featureId>TestPermsAnt.1</featureId>
  20. </item>
  21. </root>
  22. ";
  23. $xsl = '<?xml version="1.0" encoding="UTF-8"?>';
  24. $xsl .= '
  25. <xsl:stylesheet version="1.0"
  26. xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  27. xmlns:php="http://php.net/xsl">
  28. <xsl:output method="html" encoding="utf-8" indent="yes"/>
  29. <xsl:template match="root">
  30. <html><body>
  31. <h2>Items</h2>
  32. <table class="table table-bordered">
  33. <thead>
  34. <tr>
  35. <th>featureId</th>
  36. <th>item</th>
  37. </tr>
  38. </thead>
  39. <xsl:for-each select="item">
  40. <tr>
  41. <td><xsl:value-of select="featureId"/></td>
  42. <td><pre>
  43. <xsl:copy-of select="php:function(\'testFetchWfs\', string(@typeName), string(featureId))/node()"/>
  44. </pre></td>
  45. </tr>
  46. </xsl:for-each>
  47. </table>
  48. <h3>Test function to get xml content from php function</h3>
  49. <xsl:copy-of select="php:function(\'testHtmlContent\', \'test-arg-1-from-xsl\', \'test-arg-2-from-xsl\')/node()"/>
  50. </body></html>
  51. </xsl:template>
  52. </xsl:stylesheet>
  53. ';
  54. $xmldoc = new DOMDocument;
  55. $xmldoc->loadXML($xml);
  56. $xsldoc = new DOMDocument;
  57. $xsldoc->loadXML($xsl);
  58. $proc = new XSLTProcessor();
  59. $proc->registerPHPFunctions();
  60. $proc->importStyleSheet($xsldoc);
  61. $transformed = $proc->transformToXML($xmldoc);
  62. DBG::nicePrint(htmlspecialchars($xml), 'xml');
  63. DBG::nicePrint(htmlspecialchars($xsl), 'xsl');
  64. DBG::nicePrint(htmlspecialchars($transformed), 'xml transformed');
  65. echo "\n".'<hr>';
  66. echo $transformed;
  67. echo '<hr>'."\n";
  68. }
  69. }