当我包含xmlns =“ http://www.sitemaps.org/schemas/sitemap/0.9”时,XSLT不起作用]]

问题描述 投票:13回答:2

我的Google网站地图通过XSLT可以很好地呈现,并且元素中没有xmlns =“ http://www.sitemaps.org/schemas/sitemap/0.9”,但是,如果包含在内,我的foreach语句将无法正常工作,并且模板中没有任何内容。我的代码如下。感谢您的帮助。

XML

<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<url>
<loc>{site_url}</loc>
<lastmod>{current_time format="%Y-%m-%d"}</lastmod>
<changefreq>monthly</changefreq>
<priority>0.5</priority>
</url>
</urlset>

XSL

<xsl:template match="/">
<html>
<body>
<h2>Sitemap</h2>
<table border="1">
<tr bgcolor="#9acd32">
  <th>Location</th>
  <th>Last Modified</th>
  <th>Update Frequency</th>
  <th>Priority</th>
</tr>
<xsl:for-each select="urlset/url">
<tr>
  <td><xsl:value-of select="loc"/></td>
  <td><xsl:value-of select="lastmod"/></td>
  <td><xsl:value-of select="changefreq"/></td>
  <td><xsl:value-of select="priority"/></td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
    

我的Google网站地图通过XSLT可以很好地呈现,并且元素中没有xmlns =“ http://www.sitemaps.org/schemas/sitemap/0.9”,但是如果包含在内,我的foreach语句将无法正常工作。 ..

xml xslt xml-namespaces xml-sitemap
2个回答
18
投票

我的Google Sitemap通过 XSLT罚款而没有xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"但是在<urlset>元素中 当包含时,我的foreach语句 不起作用,什么也没有渲染 模板


3
投票

xpath将需要名称空间作为前缀,例如

© www.soinside.com 2019 - 2024. All rights reserved.