【问题标题】:I am trying to convert my xml document into html web page using apache mod xslt我正在尝试使用 apache mod xslt 将我的 xml 文档转换为 html 网页
【发布时间】: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?

标签: xml xslt xhtml


【解决方案1】:

您使用Hadoop Cloudera Hortonworks Other Search &amp; Big ... 输入的XML 格式不正确,因为与符号需要转义为Hadoop Cloudera Hortonworks Other Search &amp;amp; Big...。因此,您需要先将输入修正为格式正确,然后才能使用 XSLT 等 XML 工具对其进行处理。

同样将&lt;?xml-stylesheet type="txt/xsl" "href"="demo1.xsl"?&gt; 改成&lt;?xml-stylesheet type="text/xsl" href="demo1.xsl"?&gt;

【讨论】:

  • 我编辑了我的 xml 文件并将“&”替换为“and”,但现在当我到达 yourserveraddress/xml/filename.xml 时,我得到一个 xml 文件作为输出而不是 html 网页。
  • 查看我的编辑,您的处理指令有错误。
  • @MrLister,谢谢,这是发布代码中的另一个问题,我没有注意到,现在已修复。
  • @MrLister 请检查我编辑的帖子。我已将“txt”转换为“文本”,但仍然得到 XML 输出而不是 HTML。
  • @MartinHonnen 感谢您的回复。请检查我编辑的帖子。
猜你喜欢
  • 2020-11-22
  • 2014-03-08
  • 2012-09-29
  • 1970-01-01
  • 1970-01-01
  • 2010-12-26
  • 2013-06-12
  • 2015-04-24
相关资源
最近更新 更多