[ Index ]

PHP Cross Reference of phpBB-3.3.5-deutsch

title

Body

[close]

/vendor/s9e/text-formatter/src/Configurator/TemplateNormalizations/ -> InlineAttributes.php (source)

   1  <?php
   2  
   3  /**
   4  * @package   s9e\TextFormatter
   5  * @copyright Copyright (c) 2010-2021 The s9e authors
   6  * @license   http://www.opensource.org/licenses/mit-license.php The MIT License
   7  */
   8  namespace s9e\TextFormatter\Configurator\TemplateNormalizations;
   9  
  10  use DOMElement;
  11  use DOMText;
  12  
  13  /**
  14  * Inline the xsl:attribute declarations of a template
  15  *
  16  * Will replace
  17  *     <a><xsl:attribute name="href"><xsl:value-of select="@url"/></xsl:attribute>...</a>
  18  * with
  19  *     <a href="{@url}">...</a>
  20  */
  21  class InlineAttributes extends AbstractNormalization
  22  {
  23      /**
  24      * {@inheritdoc}
  25      */
  26      protected $queries = ['//*[namespace-uri() != $XSL]/xsl:attribute'];
  27  
  28      /**
  29      * {@inheritdoc}
  30      */
  31  	protected function normalizeElement(DOMElement $element)
  32      {
  33          $value = '';
  34          foreach ($element->childNodes as $node)
  35          {
  36              if ($node instanceof DOMText || $this->isXsl($node, 'text'))
  37              {
  38                  $value .= preg_replace('([{}])', '$0$0', $node->textContent);
  39              }
  40              elseif ($this->isXsl($node, 'value-of'))
  41              {
  42                  $value .= '{' . $node->getAttribute('select') . '}';
  43              }
  44              else
  45              {
  46                  // Can't inline this attribute
  47                  return;
  48              }
  49          }
  50          $element->parentNode->setAttribute($element->getAttribute('name'), $value);
  51          $element->parentNode->removeChild($element);
  52      }
  53  }


Generated: Mon Oct 4 17:42:11 2021 Cross-referenced by PHPXref 0.7.1