1

我有一个 xml 格式的站点地图,用 xsl 文件转换为 html ......当我去验证站点地图时,我有一个警告:“没有找到这个 xml 站点地图的文档类型,请检查你的语法”

这是我在尝试验证我的站点地图时收到的唯一警告......如何解决?

http://www.alecos.it/sitemap.xml <--- 这是我的 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>
  <url>
    <loc>http://www.alecos.it/diary_30012007.php</loc>
    <changefreq>daily</changefreq>
    <priority>1.0</priority>
  </url>
  <url>
    <loc>http://www.alecos.it/diary_28082006.php</loc>
    <changefreq>daily</changefreq>
    <priority>1.0</priority>
  </url>
  <url>
    <loc>http://www.alecos.it/diary_26012006.php</loc>
    <changefreq>daily</changefreq>
    <priority>1.0</priority>
  </url>
  <url>
    <loc>http://www.alecos.it/diary_25102008.php</loc>
    <changefreq>daily</changefreq>
    <priority>1.0</priority>
  </url>
  <url>
    <loc>http://www.alecos.it/diary_15072007.php</loc>
    <changefreq>daily</changefreq>
    <priority>1.0</priority>
  </url>
  <url>
    <loc>http://www.alecos.it/diary_06062005.php</loc>
    <changefreq>daily</changefreq>
    <priority>1.0</priority>
  </url>
  <url>
    <loc>http://www.alecos.it/diary_04092010.php</loc>
    <changefreq>daily</changefreq>
    <priority>1.0</priority>
  </url>
  <url>
    <loc>http://www.alecos.it/diary.php</loc>
    <changefreq>daily</changefreq>
    <priority>1.0</priority>
  </url>
  cut... cut...
</urlset>

http://www.alecos.it/sitemap.xsl <--- 这是我的站点地图 xml 的 html/css 文档

<?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">
<xsl:output method="html" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:template match="/">
<html xmlns="http://www.w3.org/1999/xhtml">
<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>

我尝试了所有方法,但没有一个目标......想法?提示?诡计?

谷歌接受我的站点地图没有错误或警告,但 xml 验证器给我一个错误/警告...谢谢

4

2 回答 2

2

这是一个如何生成所需 DOCTYPE 的示例

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
 <xsl:output method="xml" 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:strip-space elements="*"/>

 <xsl:template match="node()|@*">
     <xsl:copy>
       <xsl:apply-templates select="node()|@*"/>
     </xsl:copy>
 </xsl:template>
</xsl:stylesheet>

将此转换应用于此 XML 文档时:

<html>
 <title>Some Title</title>
 <body>
  <p>Hello, World!</p>
 </body>
</html>

它“按原样”复制文档并生成 XHTML 过渡文档类型

<!DOCTYPE html
  PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
   <title>Some Title</title>
   <body>
      <p>Hello, World!</p>
   </body>
</html>

说明

使用xsl:output:doctype-publicdoctype-system.

于 2012-08-21T12:48:52.463 回答
0

站点地图.xsl:

<?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>

效果很好,没有错误或警告,并且 sitemap.xml 现在具有正确的文档类型,可以毫无问题地对其进行验证。随心所欲地使用和分享!谢谢!

于 2012-08-22T09:51:35.500 回答