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