SHARE
TWEET

XSLT recursion depth tester

a guest Feb 11th, 2016 68 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2. ini_set('display_errors', 1);
  3. ini_set('display_startup_errors', 1);
  4. error_reporting(E_ALL);
  5.  
  6. $myxsl = <<<EOF
  7. <?xml version="1.0" encoding="UTF-8"?>
  8.  
  9. <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  10.         xmlns:php="http://php.net/xsl">
  11.  
  12. <xsl:template match="/">
  13.     <xsl:call-template name="recurse"/>
  14. </xsl:template>
  15.        
  16. <xsl:template name="recurse">
  17.     <xsl:param name="COUNT">1</xsl:param>
  18.     <xsl:value-of select="php:function('stupid', %COUNT)"/>
  19.     <xsl:if test="not(count(//Frog) = 4)">
  20.         <xsl:call-template name="recurse">
  21.             <xsl:with-param name="COUNT" select="%COUNT + 1"/>
  22.         </xsl:call-template>
  23.     </xsl:if>
  24. </xsl:template>
  25.  
  26. </xsl:stylesheet>
  27. EOF;
  28. $myxsl = str_replace('%', '$', $myxsl);
  29.  
  30. function stupid($message) {
  31.     echo "$message\n\n";
  32.     flush();
  33.     return 'yo';
  34. }
  35.  
  36. $myxml = <<<EOF
  37. <Whatever>
  38. <Frog>frog</Frog></Whatever>
  39. EOF;
  40.  
  41. $xsl = new DOMDocument();
  42. $xsl->loadXML($myxsl);
  43.  
  44. $dom0 = new DOMDocument();
  45. $dom0->loadXML($myxml);
  46.  
  47. $proc = new XSLTProcessor;
  48. $proc->registerPHPFunctions();
  49. $proc->importStyleSheet($xsl);
  50. $dom2 = $proc->transformToDoc($dom0);
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top