From 330591d5648049a682197287908994cf32f2864a Mon Sep 17 00:00:00 2001 From: Frederik Bosch Date: Thu, 5 Dec 2024 22:52:17 +0100 Subject: [PATCH] transpile --- src/Xsl/Node/AttributeName.php | 47 +++++++++++++++++++ src/Xsl/Transformer.php | 2 + test/Stubs/Xsl/ElementAttribute/attribute.xsl | 2 +- 3 files changed, 50 insertions(+), 1 deletion(-) create mode 100644 src/Xsl/Node/AttributeName.php diff --git a/src/Xsl/Node/AttributeName.php b/src/Xsl/Node/AttributeName.php new file mode 100644 index 0000000..90ef875 --- /dev/null +++ b/src/Xsl/Node/AttributeName.php @@ -0,0 +1,47 @@ +xpathCompiler = $compiler; + } + + /** + * @param DOMElement $element + * @return bool + */ + public function supports(DOMElement $element): bool + { + return $element->hasAttribute('name'); + } + + /** + * @param DOMElement $element + */ + public function transform(DOMElement $element): void + { + $element->setAttribute( + 'name', + $this->xpathCompiler->compile( + $element->getAttribute('name'), + $element + ) + ); + } +} diff --git a/src/Xsl/Transformer.php b/src/Xsl/Transformer.php index 64851e2..20619d9 100644 --- a/src/Xsl/Transformer.php +++ b/src/Xsl/Transformer.php @@ -13,6 +13,7 @@ use Genkgo\Xsl\Util\FetchNamespacesFromNode; use Genkgo\Xsl\Xpath\Compiler; use Genkgo\Xsl\Xsl\Node\AttributeExpandText; +use Genkgo\Xsl\Xsl\Node\AttributeName; use Genkgo\Xsl\Xsl\Node\AttributeValueTemplates; use Genkgo\Xsl\Xsl\Node\AttributeMatch; use Genkgo\Xsl\Xsl\Node\AttributeSelect; @@ -147,6 +148,7 @@ public static function newDefaultTransformer( new AttributeExpandText($xpathCompiler), new AttributeMatch($xpathCompiler), new AttributeSelect($xpathCompiler), + new AttributeName($xpathCompiler), new AttributeTest($xpathCompiler), new ElementValueOf(), new ElementAttribute(), diff --git a/test/Stubs/Xsl/ElementAttribute/attribute.xsl b/test/Stubs/Xsl/ElementAttribute/attribute.xsl index 38c4370..31e7390 100644 --- a/test/Stubs/Xsl/ElementAttribute/attribute.xsl +++ b/test/Stubs/Xsl/ElementAttribute/attribute.xsl @@ -5,7 +5,7 @@ - +