我有一個關於將參數從PHP代碼傳遞到xslt的問題。 這裏是我的PHP代碼:將字符串作爲參數傳遞到PHP中的XSLT中
$searchStr = 'article[@key = 'journals/acta/Saxena96']';
$xsltProcessor = new XSLTProcessor();
$xsltProcessor->registerPHPFunctions();
$xsltProcessor->importStyleSheet($this->xslDoc);
$xsltProcessor->setParameter('', 'search_condition', $searchStr);
這裏是XSLT:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="html"/>
<xsl:template match="dblp">
<form>
<table border="1">
<tr bgcolor="#9acd32">
<th style="text-align:left">Auteur</th>
<th style="text-align:left">Titre</th>
<th style="text-align:left">Pages</th>
<th style="text-align:left">Volumne</th>
<th style="text-align:left">Journal</th>
<th style="text-align:left">Numéro</th>
<th style="text-align:left">URL</th>
<th style="text-align:left">EE</th>
<th style="text-align:left">Modification</th>
</tr>
<xsl:for-each select="$search_condition">
<tr>
<td>
<xsl:value-of select="author/text()"/>
</td>
<td>
<xsl:value-of select="title/text()"/>
</td>
<td>
<xsl:value-of select="pages/text()"/>
</td>
<td>
<xsl:value-of select="volume/text()"/>
</td>
<td>
<xsl:value-of select="journal/text()"/>
</td>
<td>
<xsl:value-of select="number/text()"/>
</td>
<td>
<xsl:value-of select="url/text()"/>
</td>
<td>
<xsl:value-of select="ee/text()"/>
</td>
<td>
</td>
</tr>
</xsl:for-each>
</table>
</form>
</xsl:template>
</xsl:stylesheet>
當我運行它,我總是錯誤消息:
Warning: XSLTProcessor::transformToXml(): runtime error: file file:///D:/includes/xslt/article.xsl line 31 element for-each in D:\includes\bean\articles.php on line 67
Warning: XSLTProcessor::transformToXml(): The 'select' expression does not evaluate to a node set. in D:\includes\bean\articles.php on line 67
但是,當我直接輸入字符串條件:'文章[@key = ' journals/acta/Saxena96 ']'到xslt中,它運行良好。
感謝您的任何建議。
你見過[如何將XPath表達式作爲使用PHP的XSL參數傳遞?](http://stackoverflow.com/q/27774013/367456) – hakre