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:styleshe et xmlns:xsl="http ://www.w3.org/1999/XSL/Transform"
version='1.0'
xmlns="http://www.w3.org/TR/xhtml1/transitional"
exclude-result-prefixes="#defa ult">
<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="generat e-id(.)"/></xsl:variable>
<tr>
<td><xsl:valu e-of select="."/> (generated id=<xsl:value-of
select="\$uniqu eid"/>)</td>
</tr>
</xsl:template>
</xsl:stylesheet>
END_XSL;
$xml=new DOMDocument();
$xml->loadXML($xmlDo c);
$xsl=new XSLTProcessor() ;
$xsl->importStyleshe et(DOMDocument: :loadXML($xslDo c));
echo $xsl->transformToDoc ($xml)->saveXML()
?>