运行xmltest.php为什么会报错呢,而如果直接访问 http://127.0.0.1/xml/3.xml就是正常的,但是考虑到如果客户端不支持的话,就需要在服务端解析,调试了很久都不行。。Warning: XSLTProcessor::importStylesheet() [function.XSLTProcessor-importStylesheet]: compilation error: file file:///F%3A/www/xml/3.xsl line 2 element stylesheet in F:\www\xml\xmltest.php on line 9Warning: XSLTProcessor::importStylesheet() [function.XSLTProcessor-importStylesheet]: xsltParseStylesheetProcess : document is not a stylesheet in F:\www\xml\xmltest.php on line 9
甲班 5070 3010 乙班 2030 4050 丙班 7040 2010
文件如下:
xmltest.php<?php
$xsl = new DomDocument(); 
$xsl->load("3.xsl"); 
$inputdom = new DomDocument(); 
$inputdom->load("3.xml"); $proc = new XsltProcessor(); 
$proc->importStylesheet($xsl); 
echo $proc->transformToXML($inputdom);?>
3.xml<?xml version="1.0" encoding="GB2312"?> 
<?xml:stylesheet type="text/xsl" href="3.xsl"?> 
<document> 
<report> 
<class> 
甲班 
</class><q1>50</q1><q2>70</q2> 
<q3>30</q3><q4>10</q4></report> 
<report><class> 
乙班 
</class><q1>20</q1><q2>30</q2> 
<q3>40</q3><q4>50</q4></report> 
<report><class> 
丙班 
</class><q1>70</q1><q2>40</q2> 
<q3>20</q3><q4>10</q4></report> 
</document> 
3.xsl<?xml version="1.0" encoding="GB2312"?> 
<xsl:stylesheet xmlns:xsl="http://www.w3.org/TR/WD-xsl"> 
<xsl:template match="/"> 
<HTML><HEAD><TITLE>1999年生产统计</TITLE></HEAD> 
<BODY><xsl:apply-templates select="document"/></BODY> 
</HTML> 
</xsl:template> 
<xsl:template match="document"> 
<H3>1999年生产统计</H3> 
<TABLE border="1" cellspacing="0"> 
<TH>班组</TH><TH> 
一季度 
</TH><TH> 
二季度 
</TH> 
<TH> 
三季度 
</TH><TH> 
四季度 
</TH> 
<xsl:apply-templates select="report"/> 
</TABLE> 
</xsl:template> 
<xsl:template match="report"> 
<TR> 
<TD><xsl:value-of select="class"/></TD> 
<TD><xsl:apply-templates select="q1"/></TD> 
<TD><xsl:apply-templates select="q2"/></TD> 
<TD><xsl:apply-templates select="q3"/></TD> 
<TD><xsl:apply-templates select="q4"/></TD> 
</TR> 
</xsl:template> 
<xsl:template match="q1|q2|q3|q4"> 
<xsl:if test=".[value() $le$ 20]"> 
<xsl:attribute name="style">color:red</xsl:attribute> 
</xsl:if> 
<xsl:value-of/> 
</xsl:template> 
</xsl:stylesheet>