dsh8009271 2015-01-05 15:16
浏览 58
已采纳

XSLT处理器transformToXML没有样式信息

I am trying to use the XstlProcessor Class in PHP (version 5.5.19) to perform a xls-transformation. If I execute the script and the result gets printed, only the old xml file with no transformation is printed and it says "This XML file does not appear to have any style information associated with it.".

Part of the script which should perform the transformation:

$xml = new DomDocument;
$xml->load("tmp.xml");
$xsl = new DomDocument;
$xsl->load("bookings.xsl");

$proc = new XsltProcessor;
$proc->importStyleSheet($xsl);

$html = $proc->transformToXML($xml);
if(!$html) die('XLST processing error
');
echo $html;

The XSL-file

<?xml version="1.0" ?> 
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
  <html>
  <body>
    <h2>Booking Overview</h2>
    <table border="1">
      <tr bgcolor="#9acd32">
        <th>Date</th>
        <th>Name</th>
        <th>Surname</th>
        <th>Street</th>
        <th>City</th>
        <th>Country</th>
        <th>Brand</th>
        <th>Model</th>
      </tr>
      <xsl:for-each select="bookings/booking">
        <tr>
          <td><xsl:value-of select="@bdate" /></td>
          <td><xsl:value-of select="customer/name"/></td>
          <td><xsl:value-of select="customer/surname"/></td>
          <td><xsl:value-of select="address/street"/></td>
          <td><xsl:value-of select="address/city"/></td>
          <td><xsl:value-of select="address/country"/></td>
          <td><xsl:value-of select="vehicle/brand"/></td>
          <td><xsl:value-of select="vehicle/model"/></td>
        </tr>
      </xsl:for-each>
    </table>
  </body>
  </html>
</xsl:template>
</xsl:stylesheet>

The XML-file

<?xml version="1.0" encoding="UTF-8"?>
<!-- all bookings-->
<bookings>
<!--booking-->
<booking bdate ="2015-01-14">
    <customer>
        <name>Josef</name>
        <surname>Mongo</surname>
    </customer>
    <address>
        <street>Alberstrasse</street>
        <city>Graz</city>
        <country>Austria</country>
    </address>
    <vehicle>
        <brand>Audi</brand>
        <model>R8</model>
    </vehicle>
</booking>
<!--booking-->
<booking bdate ="2014-07-23">
    <customer>
        <name>Hannelore</name>
        <surname>Metutschnik</surname>
    </customer>
    <address>
        <street>Moserhofgasse</street>
        <city>Graz</city>
        <country>Austria</country>
    </address>
    <vehicle>
        <brand>Fiat</brand>
        <model>Punto</model>
    </vehicle>
</booking>
<!--booking-->
<booking bdate ="2014-11-20">
    <customer>
        <name>Josef</name>
        <surname>Mongo</surname>
    </customer>
    <address>
        <street>Alberstrasse</street>
        <city>Graz</city>
        <country>Austria</country>
    </address>
    <vehicle>
        <brand>BMW</brand>
        <model>M6</model>
    </vehicle>
</booking>
<!--booking-->
<booking bdate ="2014-11-23">
    <customer>
        <name>Onder</name>
        <surname>Graf</surname>
    </customer>
    <address>
        <street>Mariahilferstrasse</street>
        <city>Wien</city>
        <country>Austria</country>
    </address>
    <vehicle>
        <brand>BMW</brand>
        <model>M6</model>
    </vehicle>
</booking>
<!--booking-->
<booking bdate ="2014-11-23">
    <customer>
        <name>Onder</name>
        <surname>Graf</surname>
    </customer>
    <address>
        <street>Mariahilferstrasse</street>
        <city>Wien</city>
        <country>Austria</country>
    </address>
    <vehicle>
        <brand>BMW</brand>
        <model>M6</model>
    </vehicle>
</booking>
</bookings>
  • 写回答

1条回答 默认 最新

  • dopuz8728 2015-01-05 15:46
    关注

    Your input XML is well-formed and the XSLT code is correct. I cannot reproduce your problem under PHP 5.4.30.

    I suspect you are saving the result in a file with an *.xml extension instead of *.html. If opened with a browser, it will report that no stylesheet is associated with this XML file. So, the solution is: change the file extension.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 求数据集和代码#有偿答复
  • ¥15 关于下拉菜单选项关联的问题
  • ¥20 java-OJ-健康体检
  • ¥15 rs485的上拉下拉,不会对a-b<-200mv有影响吗,就是接受时,对判断逻辑0有影响吗
  • ¥15 使用phpstudy在云服务器上搭建个人网站
  • ¥15 应该如何判断含间隙的曲柄摇杆机构,轴与轴承是否发生了碰撞?
  • ¥15 vue3+express部署到nginx
  • ¥20 搭建pt1000三线制高精度测温电路
  • ¥15 使用Jdk8自带的算法,和Jdk11自带的加密结果会一样吗,不一样的话有什么解决方案,Jdk不能升级的情况
  • ¥15 画两个图 python或R