By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,607 Members | 1,972 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,607 IT Pros & Developers. It's quick & easy.

XSL generate-id problems

P: n/a
I used the xslt functions with php4... now i've moved to php5, and, as
the xslt functions are no longer bundled, i'm moving the code to the
XSLTProcessor class.

I've found a problem with the generate-id() XSL function... with the old
functions, generate-id() gave me the same id for the same section of my
XML document every time i processed it. Now, with the XSLTProcessor
class, every time it gives me a new id.

This is not how it's supposed to work, as it is impossible to make
references to sections of the document.

Am i doing something wrong or the new classes are a bit buggy?

thanks.
alex.
Jul 17 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
En/na alex bazan ha escrit:
I used the xslt functions with php4... now i've moved to php5, and, as
the xslt functions are no longer bundled, i'm moving the code to the
XSLTProcessor class.


I've done a bit of code for anyone who wants to test this one. I also
will be opening a bug report in php.net...

Execute the script and refresh. The ids are change each time the page is
refreshed, when they should stay the same for each node.

<?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()

?>
Jul 17 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.