网站地图xml和xsl出现问题-未找到文档类型且语法错误 [英] problems with sitemap xml and xsl - no doctype found and incorrect syntax

查看:269
本文介绍了网站地图xml和xsl出现问题-未找到文档类型且语法错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个xml格式的站点地图,这给我一个错误找不到doctype。也许源代码有问题,我希望有人帮助我纠正语法。我是xml / xsl语法的新手,所以即使站点地图可以正常工作,我也不愿对站点地图进行验证,因为我始终找不到文档类型...我使用了复制指令,以便将html输出与doctype ...

I have a sitemap in xml format which give me an error "no doctype found". Maybe there is something wrong with the source code, I hope that someone helps me with syntax corrected. I'm new at xml/xsl syntax so even if the sitemap works I have no idea to make validated my sitemap since I get always no doctype found... I used the copy instruction in order to put the html output to the browser with the doctype...

如果我尝试使用输出xml,我只会看到纯文本而不是html,并且缺少doctype ...请帮我语法...请更正我的文件...请帮助我!

If I try to use output xml I see only plain text instead of html and the doctype is missing... help me with syntax... correct my file please... help me please!

sitemap.xml:

sitemap.xml:

  <?xml version="1.0" encoding="utf-8"?>
  <?xml-stylesheet href="sitemap.xsl" type="text/xsl"?>
  <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
    <url>
      <loc>http://www.alecos.it/games.php</loc>
      <changefreq>daily</changefreq>
      <priority>1.0</priority>
    </url>
    <url>
      <loc>http://www.alecos.it/diary_31032007.php</loc>
      <changefreq>daily</changefreq>
      <priority>1.0</priority>
    </url>
    cut... cut...
  </urlset>

sitemap.xsl:

sitemap.xsl:

  <xsl:stylesheet version="2.0"
    xmlns:html="http://www.w3.org/TR/REC-html40"
    xmlns:sitemap="http://www.sitemaps.org/schemas/sitemap/0.9"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:output method="html" omit-xml-declaration="yes" indent="yes"
    doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"
    doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN"/>
  <xsl:template match="/">
  <html>
  <head>
    <title>SiteMap - Alecos Web Site By Alessandro Marinuzzi</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
  </head>
  <body>
  <div id="content">
  <h1><a href="index.php" title="Alecos Web Site"><img src="gfx/Logo.png" alt="[Alecos WebSite SiteMap]" border="0"/></a></h1>
  <div class="intro">
    <p>Generated By <a href="http://www.alecos.it/">www.alecos.it</a>. Windows, Linux, Unix, MacOS(X) and Amiga programs, scripts, translations, articles and more...</p>
    <p>This sitemap contains <xsl:value-of select="count(sitemap:urlset/sitemap:url)"/> URLs.</p>
  </div>
  <table class="sitemap" cellpadding="3">
    <thead>
      <tr>
        <th width="80%">URL</th>
        <th width="10%">Priority</th>
        <th width="10%">Change Frequency</th>
      </tr>
    </thead>
    <tbody>
      <xsl:variable name="lower" select="'abcdefghijklmnopqrstuvwxyz'"/>
      <xsl:variable name="upper" select="'ABCDEFGHIJKLMNOPQRSTUVWXYZ'"/>
      <xsl:for-each select="sitemap:urlset/sitemap:url">
        <tr>
          <td>
            <xsl:variable name="itemURL">
              <xsl:value-of select="sitemap:loc"/>
            </xsl:variable>
            <a href="{$itemURL}">
              <xsl:value-of select="sitemap:loc"/>
            </a>
          </td>
          <td>
            <xsl:value-of select="concat(sitemap:priority*100,'%')"/>
          </td>
          <td>
            <xsl:value-of select="concat(translate(substring(sitemap:changefreq, 1, 1),concat($lower, $upper),concat($upper, $lower)),substring(sitemap:changefreq, 2))"/>
          </td>
        </tr>
      </xsl:for-each>
    </tbody>
  </table>
  </div>
  </body>
  </html>
  </xsl:template>
  <xsl:copy>
  <xsl:apply-templates select="/"/>
  </xsl:copy>
  </xsl:stylesheet>


推荐答案

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0"
  xmlns:html="http://www.w3.org/TR/REC-html40"
  xmlns:image="http://www.google.com/schemas/sitemap-image/1.1"
  xmlns:sitemap="http://www.sitemaps.org/schemas/sitemap/0.9"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns="http://www.w3.org/1999/xhtml">
<xsl:output
  omit-xml-declaration="no" method="xml"
  doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN"
  doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"
  indent="yes" encoding="UTF-8"/>
<xsl:template match="/">
<html>
<head>
<title>SiteMap - Alecos Web Site By Alessandro Marinuzzi</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<style type="text/css">
body {
  font-family: Helvetica, Arial, sans-serif;
  font-size: 68.5%;
  color: #333;
}
table {
  border: none;
  border-collapse: collapse;
}
.sitemap tr.odd {
  background-color: #f7f7f7;
}
.sitemap tbody tr:hover {
  background-color: #ddf4df;
}
.sitemap tbody tr:hover td, .sitemap tbody tr:hover td a {
  color: #060;
}
a {
  color: #000;
  text-decoration: none;
}
.intro p {
  color: #060;
}
a:hover {
  text-decoration: underline;
  color: #690;
}
table {
  font-size: 1em;
  width: 100%;
}
th {
  text-align: left;
  padding: 5px;
}
thead th {
  background-color: #ccffcc;
  border-bottom: 1px solid #99cc99;
  border-top: 1px solid #99cc99;
}
tbody tr {
  border-bottom: 1px dotted #CCC;
  padding: 5px 0;
}
</style>
</head>
<body>
<div id="content">
<h1><a href="index.php" title="Alecos Web Site"><img src="gfx/Logo.png" alt="[Alecos WebSite SiteMap]" border="0"/></a></h1>
<div class="intro">
  <p>Generated By <a href="http://www.alecos.it/">www.alecos.it</a>. Windows, Linux, Unix, MacOS(X) and Amiga programs, scripts, translations, articles and more...</p>
  <p>This sitemap contains <xsl:value-of select="count(sitemap:urlset/sitemap:url)"/> URLs.</p>
</div>
<table class="sitemap" cellpadding="3">
  <thead>
    <tr>
      <th width="80%">URL</th>
      <th width="10%">Priority</th>
      <th width="10%">Change Frequency</th>
    </tr>
  </thead>
  <tbody>
    <xsl:variable name="lower" select="'abcdefghijklmnopqrstuvwxyz'"/>
    <xsl:variable name="upper" select="'ABCDEFGHIJKLMNOPQRSTUVWXYZ'"/>
    <xsl:for-each select="sitemap:urlset/sitemap:url">
      <tr>
        <td>
          <xsl:variable name="itemURL">
            <xsl:value-of select="sitemap:loc"/>
          </xsl:variable>
          <a href="{$itemURL}">
            <xsl:value-of select="sitemap:loc"/>
          </a>
        </td>
        <td>
          <xsl:value-of select="concat(sitemap:priority*100,'%')"/>
        </td>
        <td>
          <xsl:value-of select="concat(translate(substring(sitemap:changefreq, 1, 1),concat($lower, $upper),concat($upper, $lower)),substring(sitemap:changefreq, 2))"/>
        </td>
      </tr>
    </xsl:for-each>
  </tbody>
</table>
</div>
</body>
</html>
</xsl:template>
</xsl:stylesheet>

这可以与doctype声明一起使用,并且没有发现错误!我在这里发布其他有相同问题的用户的信息。这是我的sitemap.xsl的最终版本。随意共享和使用!

This works fine with doctype declaration and give me no errors found! I post here for other users that have the same problem. This is the final version of my sitemap.xsl. Share and use as you like!

这篇关于网站地图xml和xsl出现问题-未找到文档类型且语法错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆