for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
/**
* @package s9e\TextFormatter
* @copyright Copyright (c) 2010-2017 The s9e Authors
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
*/
namespace s9e\TextFormatter\Configurator\TemplateNormalizations;
use DOMAttr;
use s9e\TextFormatter\Configurator\Helpers\AVTHelper;
use s9e\TextFormatter\Configurator\Helpers\XPathHelper;
class MinifyXPathExpressions extends AbstractNormalization
{
* {@inheritdoc}
protected $queries = ['//@*[contains(., " ")]'];
protected function normalizeAttribute(DOMAttr $attribute)
$element = $attribute->parentNode;
if (!$this->isXsl($element))
// Replace XPath expressions in non-XSL elements
$this->replaceAVT($attribute);
}
elseif (in_array($attribute->nodeName, ['match', 'select', 'test'], true))
// Replace the content of match, select and test attributes of an XSL element
$element->setAttribute(
$attribute->nodeName,
XPathHelper::minify($attribute->nodeValue)
);
* Minify XPath expressions in given attribute
*
* @param DOMAttr $attribute
* @return void
protected function replaceAVT(DOMAttr $attribute)
AVTHelper::replace(
$attribute,
function ($token)
if ($token[0] === 'expression')
$token[1] = XPathHelper::minify($token[1]);
return $token;