php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #32604 generate-id() XSL function generates a different id for the same node each time
Submitted: 2005-04-06 12:42 UTC Modified: 2005-04-06 14:07 UTC
From: alex dot bazan at wanadoo dot es Assigned:
Status: Not a bug Package: XSLT related
PHP Version: 5.0.4 OS: MandrakeLinux 10.1
Private report: No CVE-ID: None
 [2005-04-06 12:42 UTC] alex dot bazan at wanadoo dot es
Description:
------------
Since the xslt functions are no longer bundled with PHP, i'm moving my code to the XSLTProcessor class.

When i used the xslt functions, the XSL generate-id() function always returned me the same auto-generated id for the same node, so i was able to send the id to other pages and use it to process the XML.

With the XSLTProcessor classes, every time i reload the page it gives me a new id for each node, so the generated ids are of no use.


Reproduce code:
---------------
<?php

$xmlDoc=<<<END_XML
<?xml version='1.0'?>
<mydoc>
	<name>Alex</name>
	<name>Gilad</name>
	<name>Abdul</name>
	<name>Diego</name>
</mydoc>
END_XML;

$xslDoc=<<<END_XSL
<?xml version='1.0'?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version='1.0' xmlns="http://www.w3.org/TR/xhtml1/transitional" exclude-result-prefixes="#default">
  <xsl:output method="html" encoding="ISO-8859-1"/>
  <xsl:strip-space elements="*"/>
	<xsl:template match="mydoc">
		<table border="0">
			<xsl:apply-templates select="*"/>
		</table>
	</xsl:template>
	<xsl:template match="name">
		<xsl:variable name="uniqueid"><xsl:value-of select="generate-id(.)"/></xsl:variable>    
		<tr>
			<td><xsl:value-of select="."/> (generated id=<xsl:value-of select="\$uniqueid"/>)</td>
		</tr>
	</xsl:template>
</xsl:stylesheet>
END_XSL;

$xml=new DOMDocument();
$xml->loadXML($xmlDoc);

$xsl=new XSLTProcessor();
$xsl->importStylesheet(DOMDocument::loadXML($xslDoc));
echo $xsl->transformToDoc($xml)->saveXML()

?>

Expected result:
----------------
Expected:

First execution:

Alex (generated id=id2299486)
Gilad (generated id=id2299489)
Abdul (generated id=id2299492)
Diego (generated id=id2273414)

Second execution:

Alex (generated id=id2299486)
Gilad (generated id=id2299489)
Abdul (generated id=id2299492)
Diego (generated id=id2273414)

Actual result:
--------------
Actual result:

First execution:

Alex (generated id=id2299486)
Gilad (generated id=id2299489)
Abdul (generated id=id2299492)
Diego (generated id=id2273414)

Second Execution:

Alex (generated id=id2431192)
Gilad (generated id=id2431196)
Abdul (generated id=id2431199)
Diego (generated id=id2431202)


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-04-06 14:07 UTC] rrichards@php.net
Sorry, but your problem does not imply a bug in PHP itself.  For a
list of more appropriate places to ask for help using PHP, please
visit http://www.php.net/support.php as this bug system is not the
appropriate forum for asking support questions.  Due to the volume
of reports we can not explain in detail here why your report is not
a bug.  The support channels will be able to provide an explanation
for you.

Thank you for your interest in PHP.

This is functionality of libxslt and the spec even states "An implementation is under no obligation to generate the same identifiers each time a document is transformed."
 
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Sun Nov 29 02:01:23 2020 UTC