我有一个简单的站点地图,其代码如下: ?xml version="1.0" encoding="utf-8"?urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"url lochome page link/loc titleEast Randolph Cabinet Shop/title levellevel-1/level/url../urls
<?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>
当此转换应用于提供的“符合google标准”的站点地图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>