代码之家  ›  专栏  ›  技术社区  ›  Julian

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

  •  12
  • Julian  · 技术社区  · 15 年前

    我的google sitemap通过xslt fine呈现良好,但在<urlset>元素中没有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>
    
    2 回复  |  直到 15 年前
        1
  •  17
  •   Dimitre Novatchev    15 年前

    xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" <urlset>

    "http://www.sitemaps.org/schemas/sitemap/0.9" "no namespace"

    urlset/url
    

    <xsl:stylesheet version="1.0"
     xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
     xmlns:s="http://www.sitemaps.org/schemas/sitemap/0.9"
     exclude-result-prefixes="s"
    >
    
     <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="s:urlset/s:url">
              <tr>
                <td><xsl:value-of select="s:loc"/></td>
                <td><xsl:value-of select="s:lastmod"/></td>
                <td><xsl:value-of select="s:changefreq"/></td>
                <td><xsl:value-of select="s:priority"/></td>
              </tr>
            </xsl:for-each>
          </table>
        </body>
      </html>
     </xsl:template>
    </xsl:stylesheet>
    

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

    <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>
             <tr>
                <td>{site_url}</td>
                <td>{current_time format="%Y-%m-%d"}</td>
                <td>monthly</td>
                <td>0.5</td>
             </tr>
          </table>
       </body>
    </html>
    
        2
  •  3
  •   Luke Schafer    15 年前

    {http://www.sitemaps.org/schemas/sitemap/0.9}urlset
    

    x:urlset
    

    http://msdn.microsoft.com/en-us/library/ms950779.aspx