#32604 [Opn->Bgs]: generate-id() XSL function generates a different id for the same node each time
| From: | rrichards@php.net | Date: | Wed, 06 Apr 2005 12:07:09 +0000 |
| Subject: | #32604 [Opn->Bgs]: generate-id() XSL function generates a different id for the same node each time | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-76437@lists.php.net to get a copy of this message | ||
ID: 32604
Updated by: rrichards@php.net
Reported By: alex dot bazan at wanadoo dot es
-Status: Open
+Status: Bogus
Bug Type: XSLT related
Operating System: MandrakeLinux 10.1
PHP Version: 5.0.4
New Comment:
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."
Previous Comments:
------------------------------------------------------------------------
[2005-04-06 12:42:19] 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)
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=32604&edit=1