PHP XSLTProcessor problem with double handlebars in attributes

Viewed 24

My problem is with the built-in xslt processor in php. It transforms the double handlebars to single ones, but only in attributes. I use the following code to test:

$xsldoc = new DOMDocument();
$xsldoc->loadXML('<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"><xsl:template match="alma"><korte malna="{{keres_keres}}">{{keres_keres}}</korte></xsl:template></xsl:stylesheet>');
$xslproc = new XSLTProcessor();
$xslproc->importStyleSheet($xsldoc);
$xmldoc = new DOMDocument();
$xmldoc->loadXML('<?xml version="1.0" encoding="UTF-8"?><alma/>');
$xmlout = $xslproc->transformToXML($xmldoc);

The result is:

<?xml version="1.0"?>
<korte malna="{keres_keres}">{{keres_keres}}</korte>

Does anybody have any idea what's happening here? Any help is greatly appreciated. I know I can use xsl:attribute to avoid this, but unfortunately I'm not the one editing the xsl. (Meanwhile it turned out that not only php's xslt works like this.)

István

1 Answers

That is not an issue with that particular processor but just a feature of the XSLT language, for many attributes and for those of literal result elements you can use "attribute value templates" which use curly braces to wrap an XPath expression, doubling them is the escape mechanism but that means that to have double curly braces in the result you need four of them in the XSLT:

<korte malna="{{{{keres_keres}}}}">
Related