我正在尝试使用 Macromedia XSLTransform 类将从 Amazon Web Services 返回的 XML 转换为 HTML。这是调用转换的 PHP 页面:
<?php
require_once('includes/MM_XSLTransform/MM_XSLTransform.class.php');
$restquery = "http://ecs.amazonaws.com/onca/xml?Service=AWSECommerceService&AWSAccessKeyId=[myid]&Operation=ItemLookup&ResponseGroup=Large&ItemId=" . htmlspecialchars($_GET["asin"]);
$mm_xsl = new MM_XSLTransform();
$mm_xsl->setXML($restquery);
$mm_xsl->setXSL("aws1.xsl");
echo $mm_xsl->Transform();
?>
这是 aws1.xsl 页面的片段
<?xml version="1.0"?>
<xsl:stylesheet
version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:aws="http://webservices.amazon.com/AWSECommerceService/2006-06-07">
<xsl:output method="html" encoding="UTF-8" omit-xml-declaration="yes"/>
<xsl:template match="aws:Item">
<html>
<body>
<table>
<tr>
<td style="border-bottom:#C0C0C0 dotted 1px;padding:10px">
<table cellpadding="0" cellspacing="0" style="width: 90%;padding:5px">
<tr>
<xsl:if test="aws:SmallImage/aws:URL">
<td valign="top" width="50">
<img>
<xsl:attribute name="src">
<xsl:value-of select="aws:SmallImage/aws:URL" disable-output-escaping="yes" />
</xsl:attribute>
<xsl:attribute name="border">0</xsl:attribute>
</img>
</td>
</xsl:if>
<!-- bunch of other stuff -->
</tr>
</table>
</td>
</tr>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
基本代码正在运行 - 我得到了有关预期 ASIN 商品的数据。而且我知道 XSL 基本上可以工作,因为如果我故意在其中放入一个无效属性,我会得到一个解析器错误。但我得到的是一大堆未格式化的文本,而不是 HTML。我尝试了各种<xsl:output method>
选择,但似乎没有一个有效。我认为这是某种编码或字符集问题。