所以,我有一个经过测试的XSLT转换工作(test.xsl)
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format" xmlns:export="http://startrek.csd.auth.gr/dr-device/export/export.rdf#" xmlns:defeasible="http://lpis.csd.auth.gr/systems/dr-device/defeasible.rdfs#" xmlns:carlo="http://lpis.csd.auth.gr/systems/dr-device/carlo/carlo-flex.rdf#">
<xsl:output method="html"/>
<xsl:template match="/">
<html>
<head>
<title/>
</head>
<body>
<br/>
<h1>Matchmaking Results</h1>
<br/>
<h2>Compatible apartments to your requirements</h2>
<br/>
<table border="1">
<tbody>
<tr>
<th><p class="p1">Apt Name</p></th>
<th><p class="p1">Centrally located</p></th>
<th><p class="p1">Price</p></th>
<th><p class="p1">Size</p></th>
<th><p class="p1">No of bedrooms</p></th>
<th><p class="p1">Floor</p></th>
<th><p class="p1">Size of the garden</p></th>
<th><p class="p1">Has a lift?</p></th>
<th><p class="p1">Allows pets?</p></th>
</tr>
<xsl:apply-templates select="//export:acceptable"/>
</tbody>
</table>
<br/>
<h2>Most suitable apartment for you</h2>
<xsl:apply-templates select="//export:rent"/>
</body>
</html>
</xsl:template>
<xsl:template match="export:acceptable">
<xsl:if test="defeasible:truthStatus='defeasibly_proven_positive'">
<xsl:variable name="apt" select="export:apartment"/>
<tr>
<td align="center">
<xsl:value-of select="$apt"/>
</td>
<td align="center">
<xsl:value-of select="document('carlo-flex_ex.rdf')//carlo:apartment[carlo:name=$apt]/carlo:central"/>
</td>
<!-- Centrally located -->
<td align="center">
<xsl:value-of select="document('carlo-flex_ex.rdf')//carlo:apartment[carlo:name=$apt]/carlo:price"/>
</td>
<!-- Price-->
<td align="center">
<xsl:value-of select="document('carlo-flex_ex.rdf')//carlo:apartment[carlo:name=$apt]/carlo:size"/>
</td>
<!-- Size-->
<td align="center">
<xsl:value-of select="document('carlo-flex_ex.rdf')//carlo:apartment[carlo:name=$apt]/carlo:bedrooms"/>
</td>
<!-- No of bedrooms-->
<td align="center">
<xsl:value-of select="document('carlo-flex_ex.rdf')//carlo:apartment[carlo:name=$apt]/carlo:floor"/>
</td>
<!-- Floor-->
<td align="center">
<xsl:value-of select="document('carlo-flex_ex.rdf')//carlo:apartment[carlo:name=$apt]/carlo:gardenSize"/>
</td>
<!-- Size of the garden-->
<td align="center">
<xsl:value-of select="document('carlo-flex_ex.rdf')//carlo:apartment[carlo:name=$apt]/carlo:lift"/>
</td>
<!-- Has a lift?-->
<td align="center">
<xsl:value-of select="document('carlo-flex_ex.rdf')//carlo:apartment[carlo:name=$apt]/carlo:pets"/>
</td>
<!-- Allows pets?-->
</tr>
<xsl:text> </xsl:text>
</xsl:if>
</xsl:template>
<xsl:template match="export:rent">
<xsl:value-of select="export:apartment"/>
</xsl:template>
</xsl:stylesheet>
当我在php中使用它时出现问题。通过在那里使用它,我只有我的网站上打印的文本(Apt Name,Centrally等),根本没有数据。
// Load the XML source
$xml = new DOMDocument;
$xml->load($response); //export.rdf
$xsl = new DOMDocument;
$xsl->load('test.xsl');
// Configure the transformer
$proc = new XSLTProcessor;
$proc->importStyleSheet($xsl); // attach the xsl rules
echo $proc->transformToXML($xml);
我无法理解为什么在php调用XSLT转换时它无效。 似乎xsl:apply-templates根本不起作用。我错过了什么吗?我应该在php或xslt代码中添加其他东西吗?任何可能的帮助将非常感谢!谢谢。
PS我使用PHP版本5.5.6启用XSL(libxslt版本1.1.2)