/** * 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.')); }
/** * Constructor * * @param util.cmd.ParamString args */ public function __construct(ParamString $args) { $dsn = new DSN($args->value(0)); $this->adapter = self::$adapters[$dsn->getDriver()]->newInstance(DriverManager::getInstance()->getConnection($dsn->dsn)); $this->package = $args->value('package', 'p', 'db'); $this->host = $args->value('host', 'h', $dsn->getHost()); $this->naming = $args->value('nstrategy', 'n', ''); if ('' != $this->naming) { DBXMLNamingContext::setStrategy(XPClass::forName($this->naming)->newInstance()); } $this->prefix = $args->value('prefix', 'pv', ''); $this->ptargets = explode('|', $args->value('ptargets', 'pt', '')); $this->pexclude = $args->value('pexclude', 'pe', FALSE); $xsls = array(); $lang = $args->value('lang', 'l', 'xp5.php'); if ($this->getClass()->getPackage()->providesPackage(strtr($lang, '.', '_'))) { $resources = $this->getClass()->getPackage()->getPackage(strtr($lang, '.', '_'))->getResources(); foreach ($resources as $resource) { $filename = substr($resource, strrpos($resource, DIRECTORY_SEPARATOR) + 1); if (substr($filename, -8, 8) !== '.php.xsl') { continue; } $xsls[] = $resource; } } else { $packagepath = strtr($this->getClass()->getPackage()->getName(), '.', DIRECTORY_SEPARATOR); $xsls[] = $packagepath . DIRECTORY_SEPARATOR . $lang . '.xsl'; } foreach ($xsls as $resource) { $processor = new DomXSLProcessor(); $processor->setBase(__DIR__); $processor->setXSLBuf(ClassLoader::getDefault()->getResource($resource)); $processor->setParam('package', $this->package); if ($this->prefix) { $processor->setParam('prefix', $this->prefix); $processor->setParam($this->pexclude ? 'exprefix' : 'incprefix', implode(',', $this->ptargets)); } $this->processor[] = $processor; } }
/** * 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(); }