【发布时间】:2016-07-24 09:58:11
【问题描述】:
这是我的 xml 文档。
<?xml version="1.0" encoding="ISO-8859-15"?>
<?xml-stylesheet type="txt/xsl" "href"="demo1.xsl"?>
<demo>
<root>
<_shards>
<total>1</total>
<failed>0</failed>
<successful>1</successful>
</_shards>
<hits>
<hits>
<highlight>
Hadoop Cloudera Hortonworks Other Search and Big Data Partners Products Technology Overview <em>Aspire</em> Content Representative Customers Case Studies Resources Blog White Papers Videos <em>Aspire</em> Downloads <em>Aspire</em> Wiki Technical Briefs Company Introducing Search Technologies Executive Team Partners Press
</highlight>
<_index>newindex3</_index>
<_type>SearchTech</_type>
<_id>http://www.searchtechnologies.com/support</_id>
<_score>0.1789403</_score>
<fields>
<keywords>keywords-NOT-PROVIDED</keywords>
<title>Search Technologies</title>
<url>http://www.searchtechnologies.com/support</url>
</fields>
</hits>
<hits>
<highlight>
Hadoop Cloudera Hortonworks Other Search and Big Data Partners Products Technology Overview <em>Aspire</em> Content Representative Customers Case Studies Resources Blog White Papers Videos <em>Aspire</em> Downloads <em>Aspire</em> Wiki Technical Briefs Company Introducing Search Technologies Executive Team Partners Press
</highlight>
<_index>newindex3</_index>
<_type>SearchTech</_type>
<_id>http://www.searchtechnologies.com/</_id>
<_score>0.1491169</_score>
<fields>
<keywords>
Enterprise Search, Big Data, Analytics, Consulting, Search Engine Experts, Big Data Services
</keywords>
<title>Enterprise Search and Big Data Experts</title>
<url>http://www.searchtechnologies.com/</url>
</fields>
</hits>
<total>2</total>
<max_score>0.1789403</max_score>
</hits>
<took>3</took>
<timed_out>false</timed_out>
</root>
</demo>
这是我的 xslt 代码。我试图从我的 xml 中仅过滤突出显示字段。 match 属性用于将模板与 XML 元素相关联。
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<body>
<h2>My DEMO</h2>
<table border="1">
<tr bgcolor="#9acd32">
<th>highlight</th>
</tr>
<xsl:for-each select="demo/root/hits/hits">
<tr>
<td><xsl:value-of select="highlight"/></td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
当我访问我的服务器时:http://yourserveraddress/xml/filename.xml 我收到一条错误消息,提示“此 XML 文件似乎没有任何与之关联的样式信息”
我进行了更正并将“txt”转换为“文本”,现在当我转到我的服务器时,我得到了以下输出而不是 html 网页。
此 XML 文件似乎没有任何关联的样式信息。文档树如下所示。
<?xml-stylesheet type="text/xsl" "href"="demo1.xsl"?>
<demo>
<root>
<_shards>
<total>1</total>
<failed>0</failed>
<successful>1</successful>
</_shards>
<hits>
<hits>
<highlight>
Hadoop Cloudera Hortonworks Other Search and Big Data Partners Products Technology Overview
<em>Aspire</em>
Content Representative Customers Case Studies Resources Blog White Papers Videos
<em>Aspire</em>
Downloads
<em>Aspire</em>
Wiki Technical Briefs Company Introducing Search Technologies Executive Team Partners Press
</highlight>
<_index>newindex3</_index>
<_type>SearchTech</_type>
<_id>http://www.searchtechnologies.com/support</_id>
<_score>0.1789403</_score>
<fields>
<keywords>keywords-NOT-PROVIDED</keywords>
<title>Search Technologies</title>
<url>http://www.searchtechnologies.com/support</url>
</fields>
</hits>
<hits>
<highlight>
Hadoop Cloudera Hortonworks Other Search and Big Data Partners Products Technology Overview
<em>Aspire</em>
Content Representative Customers Case Studies Resources Blog White Papers Videos
<em>Aspire</em>
Downloads
<em>Aspire</em>
Wiki Technical Briefs Company Introducing Search Technologies Executive Team Partners Press
</highlight>
<_index>newindex3</_index>
<_type>SearchTech</_type>
<_id>http://www.searchtechnologies.com/</_id>
<_score>0.1491169</_score>
<fields>
<keywords>
Enterprise Search, Big Data, Analytics, Consulting, Search Engine Experts, Big Data Services
</keywords>
<title>Enterprise Search and Big Dataà Experts</title>
<url>http://www.searchtechnologies.com/</url>
</fields>
</hits>
<total>2</total>
<max_score>0.1789403</max_score>
</hits>
<took>3</took>
<timed_out>false</timed_out>
</root>
</demo>
【问题讨论】:
-
“下面是第一个错误之前的页面呈现” -- 您是否忘记在帖子中包含 XML?