【发布时间】:2013-12-01 11:11:30
【问题描述】:
我希望有人可以帮助我我被困了一段时间..
我是附属公司,我从提供的获取 xml 数据。我正在尝试转换此数据并在我的网站上显示为 html。
我已经测试了我的 xsl,并且可以确认 xsl 正在按我想要的方式显示数据。
我的问题是从 urla 中提取数据并使用 xsl 转换数据以显示 html 的 php 代码不起作用。
<?php
$context = stream_context_create(array('http' => array('header' => 'Accept: application/xml')));
$url = 'http://merchandising.expediaaffiliate.com/campaign/?campaignId=85413&cid=409870 ';
$xml = file_get_contents($url, false, $context);
$xml = simplexml_load_string($xml);
$doc = new DOMDocument();
$doc->load('http://sitename/hotels.xslt');
$xsl = new XSLTProcessor();
$xsl->importStyleSheet($doc);
$doc->load($xml);
echo $xsl->transformToXML($doc);
?>
我的 XSl 如下:
<?xml version="1.0" encoding="ISO-8859-1"?>
<html xsl:version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns="http://www.w3.org/1999/xhtml">
<body style="font-family:Arial;font-size:12pt;background-color:#EEEEEE">
<xsl:for-each select="HotelAvailabilityListResults">
<xsl:for-each select="Hotel">
<div style="background-color:teal;color:white;padding:4px">
<span style="font-weight:bold"><xsl:value-of
select="name"
disable-output-escaping="yes"/></span>
- <xsl:value-of select="city"/>
</div>
<div style="margin-left:20px;margin-bottom:1em;font-size:10pt">
<p><xsl:value-of select="shortDescription"
disable-output-escaping="yes"/>.
<span style="font-style:italic">
<xsl:value-of select="address1"
disable-output-escaping="yes"/>
</span>.</p>
<p>
<span style="font-style:italic">
<xsl:element name="img">
<xsl:attribute name="src">
<xsl:value-of select="thumbNailUrl"/>
</xsl:attribute>
</xsl:element>
</span>.</p>
</div>
<span style="font-style:italic">
<xsl:value-of select="HotelProperty/promoDescription" />
</span>
<span style="font-style:italic">
<xsl:value-of select="ValueAdds/ValueAdd" />
</span>
<div>
<span style="font-style:italic">
<xsl:element name="a">
<xsl:attribute name="href">
<xsl:value-of select="hotelUrl"/>
</xsl:attribute>
</xsl:element>
</span>
</div>
</xsl:for-each>
</xsl:for-each>
</body>
</html>
【问题讨论】:
-
您能否详细解释一下您的设置中的不工作是什么意思?
-
除非有充分的理由,否则为什么不让客户处理转换呢?只需将样式表声明添加到 XML-
<?xml-stylesheet type="text/xsl" href="(url of your .xsl file)" ?>
标签: php xml xslt xhtml affiliate