2016-04-04 31 views
0

這是我的xml文檔。我想將我的xml文檔轉換爲使用apache mod xslt的html網頁

<?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只過濾突出顯示字段。匹配屬性用於將模板與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> 
+0

_」下面是頁面渲染到第一個錯誤「_ - 你忘了在你的文章中包含XML嗎? –

回答

0

您與Hadoop Cloudera Hortonworks Other Search & Big ...輸入不是格式良好的XML作爲符號需要轉義爲Hadoop Cloudera Hortonworks Other Search &amp; Big...。因此,您需要在使用XSLT之類的XML工具處理輸入之前,將輸入修復爲良構。

也正確<?xml-stylesheet type="txt/xsl" "href"="demo1.xsl"?><?xml-stylesheet type="text/xsl" href="demo1.xsl"?>。 「

+0

我編輯了我的xml文件,用「and」替換了「&」,但是現在當我訪問http://yourserveraddress/xml/filename.xml時,我得到一個xml文件作爲輸出而不是html網頁。 – Rose

+0

查看我的編輯,處理指令中有錯誤。 –

+0

@MrLister,謝謝,這是發佈的代碼中的另一個問題,我沒有注意到,現在已修復。 –