开发者

PHP XSL output issue

I have an issue of using PHP 5's XSLTProcessor to manipulate the following XML document. The issue is not the output being processed by the XSLT but elements of the html output are getting xmlns:php="http://php.net/xsl" added to them. An example is below.

The PHP:

$xmldoc = DOMDocument::load($xml);
$xsldoc = DOMDocument::load($xslt开发者_开发技巧);
$proc = new XSLTProcessor();
$proc->registerPHPFunctions();
$proc->importStyleSheet($xsldoc);
echo $proc->transformToXML($xmldoc);

The XML:

<allusers>
 <user>
  <uid>bob</uid>
 </user>
 <user>
  <uid>tom</uid>
 </user>
</allusers>

The XSLT:

 <?xml version="1.0"?>
 <xsl:stylesheet version="1.0" 
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:php="http://php.net/xsl"
  xsl:extension-element-prefixes="php">

 <xsl:output method="html" indent="yes" omit-xml-declaration="yes"/>

 <xsl:template match="allusers">
  <h2>Users</h2>
  <table>
   <xsl:for-each select="user">
   <tr><td>
    <xsl:value-of select="php:function ('MyClass::firstLetter',string(.))"/>
   </td></tr>
   </xsl:for-each>
  </table>
 </xsl:template>

 </xsl:stylesheet>

And the odd output (notice the xmlns:php="http://php.net/xsl"):

<!DOCTYPE html> 
<html> 
<head></head>
<body>
 <h2 xmlns:php="http://php.net/xsl">Users</h2>
 <table xmlns:php="http://php.net/xsl">
  <tr><td>b</td></tr>
  <tr><td>t</td></tr>
 </table>
</body>
</html>

Any ideas? I'm sure that I have all the imports I need and am using them correctly but if someone can show me what or where I'm going wrong, that would be great. Thanks in advance.


 <xsl:stylesheet version="1.0"    
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"   
  xmlns:php="http://php.net/xsl"   
  xsl:extension-element-prefixes="php">

You need to add:

 exclude-result-prefixes="php" 

The exclude-result-prefixes attribute designates a list of prefixes and the namespaces bound to these prefixes are to be excluded (not copied) on literal result elements.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜