|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #39299 Using a xsl variable in a xsl:key macth attribute does not work
Submitted: 2006-10-29 15:24 UTC Modified: 2006-10-31 06:21 UTC
From: pascal dot heus at gmail dot com Assigned:
Status: Not a bug Package: XSLT related
PHP Version: 5.1.6 OS: GNU/Linux
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: pascal dot heus at gmail dot com
New email:
PHP Version: OS:


 [2006-10-29 15:24 UTC] pascal dot heus at gmail dot com
The following xsl code works fine with the Sablotron engine under pHp4 or with XMLSpy:

<xsl:key name="course-key" match="/gmu/programs/program[@id=$program-id]//courseRef" use="concat(@subject,@course,@subcourse)"/>

When using libxslt under pHp 5, it fails to execute.

The problem comes form the $program-id variable used in the match= attribute. If I replace it with a hard coded value, the XSLT works fine:
<xsl:key name="course-key" match="/gmu/programs/program[@id='csi-phd-qis']//courseRef" use="concat(@subject,@course,@subcourse)"/>

This is under pHp 5.0.4 running on an institutional server, I don't have the authority to upgrade that system for further testing.

Reproduce code:
You can retrieve the xslt and xml file at:


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2006-10-29 17:18 UTC]
Thank you for this bug report. To properly diagnose the problem, we
need a short but complete example script to be able to reproduce
this bug ourselves. 

A proper reproducing script starts with <?php and ends with ?>,
is max. 10-20 lines long and does not require any external 
resources such as databases, etc. If the script requires a 
database to demonstrate the issue, please make sure it creates 
all necessary tables, stored procedures etc.

Please avoid embedding huge scripts into the report.

 [2006-10-30 02:23 UTC] pascal dot heus at gmail dot com
// Code to illustrate bug #39299
// Differences in XSLT's are at lines 56/57
echo 'pHp '.phpversion();
$xmlDom = new DomDocument();
$xslDom = new DomDocument();
// Comment/uncomment lines below to select XSLT file
$xsl = '';
//$xsl = '';

echo "<p>Using $xsl</p>";
$proc = new XsltProcessor();
$xslDom = $proc->importStylesheet($xslDom);
$outputDom = $proc->transformToDoc($xmlDom);
echo $outputDom->saveHTML();
 [2006-10-30 08:13 UTC]
I don't even know, what's your expected output and I'm not in the mood (nor do i have the time) to analyse your xslt.

Please provide a as small as possible script/xslts and tell me, what your expected output is and what you get.

But at the end, I doubt it's a php issue, but a libxslt one, so you may better go there directly (try with the commandline tool xsltproc, if you get the wrong result there as well, it's defintively not a php issue...)
 [2006-10-30 12:17 UTC] pascal dot heus at gmail dot com
I guess we're both individuals with little time and varying moods. Agree it's actually likely to be a libxslt problem, I may try to report it there. 

If someone else ever reports something like this not working:
<xsl:key name="my-key" match="$my-var" use="my-element"/>
you know where it comes from: can't use a $variable in the match="" attribute.

Have a nice day/night and thanks for making pHp such great product.
 [2006-10-31 06:21 UTC]
I close this bug for now, as it doesn't look like a php issue.
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Wed Apr 14 04:01:24 2021 UTC