/** * Entry point * * @param string[] args */ public static function main($args) { $proc = new DomXSLProcessor(); $proc->setXMLFile('XP_CodeSniffer/SQLI/CodeSniffer/Standards/xp/Reports/config.xml'); $proc->setXSLBuf(' <xsl:stylesheet version="1.0" encoding="UTF-8" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" > <xsl:template match="/" xml:space="preserve"> <xsl:for-each select="/report/event[@code != \'RC_DYNAMIC_ERROR\' and @code != \'RC_DYNAMIC_WARNING\']"> <rule key="{sniffer}/{@code}" priority="{priority}"> <category name="{category}" /> <name>XP: <xsl:value-of select="name" /></name> <configKey>rulesets/<xsl:value-of select="@code" /></configKey> <description><xsl:value-of select="message" /></description> </rule></xsl:for-each> </xsl:template> </xsl:stylesheet> '); try { $proc->run(); } catch (TransformerException $e) { $e->printStackTrace(); exit(1); } // Get result $result = $proc->output(); $result = ' ' . trim(str_replace('<?xml version="1.0"?>', '', $result)); echo $result; }
public function fileAsXslFileWithRelativeIncludeDoesNotWork() { $t = NULL; $proc = new DomXSLProcessor(); $style = new DOMDocument(); $style->load('res://net/xp_framework/unittest/core/resourceprovider/two/IncludingStylesheet.xsl'); $proc->setXSLDoc($style); $proc->setXmlBuf('<document/>'); $proc->run(); $this->assertTrue(FALSE !== strpos($proc->output(), 'Include has been called.')); }
/** * Runs a transformation * * @param string xml * @param string callback * @param string[] arguments * @param string xslEncoding default 'utf-8' * @return string */ protected function runTransformation($xml, $callback, $arguments, $xslEncoding = 'utf-8') { sscanf($callback, '%[^:]::%s', $name, $method); $p = new DomXSLProcessor(); $p->registerInstance('this', $this); $p->setXMLBuf($xml); $p->setXSLBuf(sprintf('<?xml version="1.0" encoding="%s"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:php="http://php.net/xsl" > <xsl:output method="text"/> <xsl:template match="/"> <xsl:value-of select="php:function(\'XSLCallback::invoke\', \'%s\', \'%s\'%s)"/> </xsl:template> </xsl:stylesheet> ', $xslEncoding, $name, $method, $arguments ? ', ' . implode(', ', $arguments) : '')); $p->run(); return $p->output(); }