xref: /PHP-8.3/ext/xsl/tests/bug69168.phpt (revision 1925855c)
1--TEST--
2bug #69168 (DomNode::getNodePath() returns invalid path)
3--EXTENSIONS--
4xsl
5--FILE--
6<?php
7$xml = <<<EOB
8<allusers><user><uid>bob</uid></user><user><uid>joe</uid></user></allusers>
9EOB;
10$xsl = <<<EOB
11<?xml version="1.0" encoding="UTF-8"?>
12<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:php="http://php.net/xsl">
13 <xsl:template match="allusers">
14    <xsl:for-each select="user">
15      <xsl:value-of select="php:function('getPath',uid)"/><br />
16    </xsl:for-each>
17 </xsl:template>
18</xsl:stylesheet>
19EOB;
20
21function getPath($input){
22  $input[0]->nodeValue .= 'a';
23  return $input[0]->getNodePath() . ' = ' . $input[0]->nodeValue;
24}
25
26$proc = new XSLTProcessor();
27$proc->registerPHPFunctions();
28$xslDoc = new DOMDocument();
29$xslDoc->loadXML($xsl);
30@$proc->importStyleSheet($xslDoc);
31$xmlDoc = new DOMDocument();
32$xmlDoc->loadXML($xml);
33echo @$proc->transformToXML($xmlDoc);
34
35// Tests modification of the nodes
36var_dump($xmlDoc->firstChild->firstChild->firstChild->getNodePath());
37var_dump($xmlDoc->firstChild->firstChild->firstChild->nodeValue);
38?>
39--EXPECT--
40<?xml version="1.0"?>
41/allusers/user[1]/uid = boba<br/>/allusers/user[2]/uid = joea<br/>
42string(21) "/allusers/user[1]/uid"
43string(4) "boba"
44