my xsl stylesheet just works fine except the thing that i cant use attributes in my stylesheet. But i really need them to complete my function.
I’m using the xsl in php and when i try to declare an attribute and use , the xsl thinks that $attr is a php variable and the function crashes.
This is my code
<?php
function releaseNotes($source, $type, $order_by, $sort) {
$type = $type ? "[@type='{$type}']" : "";
$xsl = <<<XSL
<?xml version="1.0" encoding="iso-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:key name="versions" match="issue" use="fix_versions"/>
<xsl:key name="type" match="issue" use="concat(fix_versions, '+', @type)"/>
<xsl:template match="issues">
<xsl:for-each select="//issue[generate-id(.)=generate-id(key('versions', fix_versions)[1])]">
<xsl:sort select="fix_versions" order="descending"/>
<div class="release">
<a href="" class="version"><xsl:value-of select="fix_versions"/></a>
<xsl:attribute name="version"><xsl:value-of select="fix_versions"/></xsl:attribute>
<xsl:value-of select="$version"/>
<xsl:if test="//release[@version = '$version']">
Yeah
</xsl:if>
<div class="version" style="display:none;">
<xsl:for-each select="key('versions', fix_versions)">
<xsl:for-each select="key('type', concat(fix_versions, '+', @type))">
<div style="border-bottom:1px solid grey;">
<a href="" class="title"><xsl:value-of select="title"/></a>
<div class="toggle" style="display:none;">
<xsl:value-of select="description"/>
</div>
</div>
</xsl:for-each>
</div>
</div>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
XSL;
$xmldoc = new DOMDocument('1.0', 'utf-8');
$xmldoc->load($source);
$xsldoc = DOMDocument::loadXML($xsl);
$proc = new XSLTProcessor();
$proc->registerPHPFunctions();
$proc->importStyleSheet($xsldoc);
return $proc->transformToXML($xmldoc);
}
?>
No matter where i try to use an attribute – as soon as i want to use it, i get no result of the function anymore? Any idea?
Seems to be useless in this example but i want to check if there is a node “release” with this version number so i need to get the version of the current string as an attribute.
The xml structure is like this
<release version="x.x.x" name="release1"/>
<release version="x.x.x" name="release2"/>
<release version="x.x.x" name="release3"/>
<issues>
<issue><fix_versions>x.x.x</fix_versions></issue>
<issue><fix_versions>x.x.x</fix_versions></issue>
<issue><fix_versions>x.x.x</fix_versions></issue>
</issues>
Only issues of already released versions should be visible. Thats why i have to check for the issue if there is an release with the same version
Everything works fine, even grouping, but the attributes. As i said the function takes $version just as a php variable instead of the name of the aatribute.
Thanks in advance
Your question is a little confusing, but if you mean the problem is that:
gets translated as $type is a variable and gets expanded, if you put a \ in front of the variable, it will work, or even in single quotes: