我有以下PHP代碼,但它不起作用。我沒有看到任何錯誤,但也許我只是失明。我在PHP 5.3.1上運行這個。獲取exsl:node-set在PHP中工作
<?php
$xsl_string = <<<HEREDOC
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0"
xmlns="http://www.w3.org/1999/xhtml"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:exsl="http://exslt.org/common"
extension-element-prefixes="exsl">
<xsl:template match="/">
<p>Hello world</p>
<xsl:variable name="person">
<firstname>Foo</firstname>
<lastname>Bar</lastname>
<email>[email protected]</email>
</xsl:variable>
<xsl:value-of select="exsl:node-set(\$person)/email"/>
</xsl:template>
</xsl:stylesheet>
HEREDOC;
$xml_dom = new DOMDocument("1.0", "utf-8");
$xml_dom->appendChild($xml_dom->createElement("dummy"));
$xsl_dom = new DOMDocument();
$xsl_dom->loadXML($xsl_string);
$xsl_processor = new XSLTProcessor();
$xsl_processor->importStyleSheet($xsl_dom);
echo $xsl_processor->transformToXML($xml_dom);
?>
此代碼應該輸出「Hello world」後跟「[email protected]」,但電子郵件部分不會顯示。任何想法有什麼不對?
-Geoffrey李
很好的問題(+1)。請參閱我的答案以獲得解釋和完整解決方案。 – 2010-06-01 13:07:42