如何使用xsl转换具有属性而不是标记的xml站点地图?

如何使用xsl转换具有属性而不是标记的xml站点地图?,xml,xslt,Xml,Xslt,我有一个简单的网站地图,其代码如下: <?xml version="1.0" encoding="utf-8"?> <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"> <url> <loc>home page link</loc> <title>East Randolph Cabinet Shop</title> <

我有一个简单的网站地图,其代码如下:

<?xml version="1.0" encoding="utf-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<url>
    <loc>home page link</loc>
    <title>East Randolph Cabinet Shop</title>
    <level>level-1</level>
</url>
.
.
</urlset>

主页链接
东伦道夫橱柜店
一级
.
.
我可以使用以下xsl轻松转换为在网页上显示所需的方式:

<xsl:stylesheet
version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:sm="http://www.sitemaps.org/schemas/sitemap/0.9">

<xsl:template match="/">
<h2>Sitemap</h2>
<p>You can use our sitemap to easily navigate to any section of our website. If you still cannot find the information you need don't hesitate to <a href="contact.php">contact</a> us.</p>
<ul>
    <xsl:for-each select="sm:urlset/sm:url">
        <li class="{sm:level}">
            <a href="{sm:loc}"><xsl:value-of select="sm:title"/></a>
        </li>
    </xsl:for-each>
</ul>
</xsl:template>

</xsl:stylesheet>

网站地图
您可以使用我们的网站地图轻松导航到我们网站的任何部分。如果您仍然找不到所需的信息,请与我们联系

问题是,当我用谷歌测试我的网站地图时,它会对所有无法识别的标签(标题和级别)发出警告。我是否可以重写xml以使用每个属性,而不是无法识别的标记,使其看起来像:

<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<url>
    <loc title='East Randolph Cabinet Shop' level='level-1'>home page link</loc>
</url>
.
.
</urlset>

主页链接
.
.

我已经用谷歌测试过了,没有收到任何警告或错误。我的问题是如何将xsl重写为与以前相同的html显示方式?

这是对提供的转换的一个小调整:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
 xmlns:sm="http://www.sitemaps.org/schemas/sitemap/0.9">

 <xsl:template match="/">
    <html>
        <h2>Sitemap</h2>
        <p>You can use our sitemap to easily navigate to any section of our website. If you still cannot find the information you need don't hesitate to <a href="contact.php">contact</a> us.</p>
        <ul>
            <xsl:for-each select="sm:urlset/sm:url/sm:loc">
                <li class="{@level}">
                    <a href="{.}"><xsl:value-of select="@title"/></a>
                </li>
            </xsl:for-each>
        </ul>
    </html>
 </xsl:template>
</xsl:stylesheet>

网站地图
您可以使用我们的网站地图轻松导航到我们网站的任何部分。如果您仍然找不到所需的信息,请与我们联系

当此转换应用于提供的“谷歌兼容”站点地图XML文档时:

<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
    <url>
        <loc title='East Randolph Cabinet Shop' level='level-1'>home page link</loc>
    </url>
.
.
</urlset>
<html xmlns:sm="http://www.sitemaps.org/schemas/sitemap/0.9">
   <h2>Sitemap</h2>
   <p>You can use our sitemap to easily navigate to any section of our website. If you still cannot find the information you need
      don't hesitate to <a href="contact.php">contact</a> us.
   </p>
   <ul>
      <li class="level-1"><a href="home page link">East Randolph Cabinet Shop</a></li>
   </ul>
</html>

主页链接
.
.
生成所需的正确结果:

<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
    <url>
        <loc title='East Randolph Cabinet Shop' level='level-1'>home page link</loc>
    </url>
.
.
</urlset>
<html xmlns:sm="http://www.sitemaps.org/schemas/sitemap/0.9">
   <h2>Sitemap</h2>
   <p>You can use our sitemap to easily navigate to any section of our website. If you still cannot find the information you need
      don't hesitate to <a href="contact.php">contact</a> us.
   </p>
   <ul>
      <li class="level-1"><a href="home page link">East Randolph Cabinet Shop</a></li>
   </ul>
</html>

网站地图
您可以使用我们的网站地图轻松导航到我们网站的任何部分。如果您仍然无法找到所需的信息
别犹豫,欢迎光临。


我知道这个答案与这个问题有间接关系,但如果你有一个非常基本的Google站点地图结构,那么这对我来说很有用:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
 xmlns:sm="http://www.sitemaps.org/schemas/sitemap/0.9">

 <xsl:template match="/">
    <html>
        <h2>Sitemap</h2>
          <ul>
            <xsl:for-each select="sm:urlset/sm:url">
                <li>
                    <a href="{sm:loc}"><xsl:value-of select="sm:loc"/></a>
                </li>
            </xsl:for-each>
        </ul>
    </html>
 </xsl:template>
</xsl:stylesheet>

网站地图

谢谢你,迪米特。这非常有效,解决了谷歌警告的问题。非常感谢