运行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>
甲班 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>
解决方案 »
- php问题
- Data truncated for column 'spending' at row 1
- PHP 读取大文件尾部20行
- LINUX做服务器的该怎么来分配这台机子?
- 有没有大陆和香港的IP数据库?(只用于大陆和香港的位置判断,不用精确,QQ纯真的数据太多了)
- yayad是什么烂玩意?
- input type="file" 中文件名和路径的总长度的默认值是多少?
- session_destroy()无法注销;
- 如何在论坛中实现显示在线用户表
- php和c通过socket通信,如何~?
- php 中的模擬多線程哦
- php 里面怎么执行类似java servlet 里面 pageContext.forward的代码
班组 一季度 二季度 三季度 四季度
甲班 50 70 30 10
乙班 20 30 40 50
丙班 70 40 20 10