php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #69168 DomNode::getNodePath() returns invalid path
Submitted: 2015-03-03 10:09 UTC Modified: 2023-01-19 13:08 UTC
From: juha dot ikavalko at agentit dot fi Assigned: cmb (profile)
Status: Closed Package: XSLT related
PHP Version: 7.4 OS: Linux, Debian
Private report: No CVE-ID: None
 [2015-03-03 10:09 UTC] juha dot ikavalko at agentit dot fi
Description:
------------
DomNode::getNodePath() returns invalid output when node is passed to php function from XSLT.

php 5.6.4  - doesn't work
php 5.5.19 - doesn't work
php 5.4.35 - doesn't work
php 5.4.10 - OK
php 5.4.4  - OK
php 5.3.3  - OK
php 5.2    - OK

Test script:
---------------
$xml = <<<EOB
<allusers><user><uid>bob</uid></user><user><uid>joe</uid></user></allusers>
EOB;
$xsl = <<<EOB
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:php="http://php.net/xsl">
 <xsl:template match="allusers">
    <xsl:for-each select="user">
      <xsl:value-of select="php:function('getPath',uid)"/><br />
    </xsl:for-each>
 </xsl:template>
</xsl:stylesheet>
EOB;

function getPath($input){
  return $input[0]->getNodePath() . ' = ' . $input[0]->nodeValue;
}

$proc = new XSLTProcessor();
$proc->registerPHPFunctions();
@$proc->importStyleSheet(DOMDocument::loadXML($xsl));
echo @$proc->transformToXML(DOMDocument::loadXML($xml));

Expected result:
----------------
/allusers/user[1]/uid = bob
/allusers/user[2]/uid = joe

Actual result:
--------------
/uid = bob
/uid = joe

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2021-09-20 12:46 UTC] cmb@php.net
-Status: Open +Status: Verified -PHP Version: Irrelevant +PHP Version: 7.4
 [2021-09-20 12:46 UTC] cmb@php.net
I can confirm the erroneous behavior with PHP-7.4 and libxml2
2.9.10.
 [2023-01-19 13:08 UTC] cmb@php.net
-Status: Verified +Status: Closed -Assigned To: +Assigned To: cmb
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Nov 12 19:01:28 2024 UTC