php.net |  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
 [2006-10-29 15:24 UTC] pascal dot heus at gmail dot com
Description:
------------
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:
http://scs.gmu.edu/~rgomez/qc/xml/gmu_program_schedule_bug.xslt
http://scs.gmu.edu/~rgomez/qc/xml/gmu.xml



Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-10-29 17:18 UTC] chregu@php.net
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
<?php
// Code to illustrate bug #39299
// Differences in XSLT's are at lines 56/57
echo 'pHp '.phpversion();
$xmlDom = new DomDocument();
$xmlDom->load('http://scs.gmu.edu/~rgomez/qc/xml/gmu.xml');
$xslDom = new DomDocument();
// Comment/uncomment lines below to select XSLT file
$xsl = 'http://scs.gmu.edu/~rgomez/qc/xml/gmu_program_schedule_bug_fails.xslt';
//$xsl = 'http://scs.gmu.edu/~rgomez/qc/xml/gmu_program_schedule_bug_works.xslt';

echo "<p>Using $xsl</p>";
$xslDom->load($xsl);
$proc = new XsltProcessor();
$xslDom = $proc->importStylesheet($xslDom);
$outputDom = $proc->transformToDoc($xmlDom);
echo $outputDom->saveHTML();
?>
 [2006-10-30 08:13 UTC] chregu@php.net
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] chregu@php.net
I close this bug for now, as it doesn't look like a php issue.
 
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Sun Dec 15 10:01:25 2019 UTC