Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Xml Google多语言站点地图/xhtml:link的正确XSLT语法_Xml_Xslt_Sitemap - Fatal编程技术网

Xml Google多语言站点地图/xhtml:link的正确XSLT语法

Xml Google多语言站点地图/xhtml:link的正确XSLT语法,xml,xslt,sitemap,Xml,Xslt,Sitemap,我有一个使用xhtml:link标记的多语言站点的XML站点地图 语法如下所示: <url> <loc>http://www.example.com/url-segment/</loc> <xhtml:link rel="alternate" hreflang="en" href="http://www.example.com/url-segment/" /> <xh

我有一个使用xhtml:link标记的多语言站点的XML站点地图

语法如下所示:

        <url>
          <loc>http://www.example.com/url-segment/</loc>
          <xhtml:link rel="alternate" hreflang="en" href="http://www.example.com/url-segment/" />
          <xhtml:link rel="alternate" hreflang="de" href="http://www.example.com/de/url-segment/" />
          <xhtml:link rel="alternate" hreflang="fr" href="http://www.example.com/fr/url-segment/" />
          <lastmod>2016-08-09T00:41:57+12:00</lastmod>
          <changefreq>weekly</changefreq>
          <priority>0.9</priority>
        </url>
  <xsl:for-each select="sitemap:urlset/sitemap:url">
    <tr>
      <td>
        <xsl:variable name="itemURL">
          <xsl:value-of select="sitemap:loc"/>
        </xsl:variable>
      </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>
     <td>
       <xsl:value-of select="concat(substring(sitemap:lastmod,0,11),concat(' ', substring(sitemap:lastmod,12,5)))"/>
     </td>
   </tr>
 </xsl:for-each>
<xsl:for-each select="xhtml:link">
  <tr>
    <td>
      <xsl:value-of select="xhtml:link@href"/>
    </td>
    <td>
      <xsl:value-of select="xhtml:link@hreflang"/>
    </td>
    <td colspan="2"></td>
  </tr>
</xsl:for-each>
但这不起作用

在Google多语言站点地图中循环/选择xhtml:link标记的正确XSLT语法是什么?

您已经在xsl:for-each中的xhtml:link节点中了。使用

<xsl:value-of select="@href"/>


我无法让它使用以下代码识别/引用xhtml:link节点:

<xsl:for-each select="xhtml:link">
最终,这种方法对我起了作用:

<xsl:for-each select="./*[@rel='alternate']">
  <tr>
    <td>
      <xsl:value-of select="@href"/>
    </td>
    <td>
      <xsl:value-of select="@hreflang"/>
    </td>
  </tr>
</xsl:for-each>

我想要的东西和Barong铆接一个带有xhtml的站点地图一样:链接标签可以很好地显示在浏览器中。我发现Pedro Borges的xsl模板非常有效

该模板使用xsl:apply-templates-apply-templates处理当前节点}的所有子节点,而不是使用xsl:for-each循环通过每个xhtml链接

Pedro模板的关键部分包括:

<xsl:template match="/">
    <html>
        <body>
            …
            <xsl:apply-templates/>
            …
        </body>
    </html>
</xsl:template>

<xsl:template match="sitemap:urlset">
    …
    <xsl:for-each select="sitemap:url">
        …
        <xsl:apply-templates select="xhtml:*"/>
        …
    </xsl:for-each>
    …
</xsl:template>

<xsl:template match="xhtml:link">
    <xsl:variable name="altloc">
        <xsl:value-of select="@href"/>
    </xsl:variable>
    <p>
        Alt language version: 
        <a href="{$altloc}">
            <xsl:value-of select="@href"/> 
        </a> 
        –
        <xsl:if test="@hreflang">
            <xsl:value-of select="@hreflang"/> 
        </xsl:if> 
    </p>
</xsl:template>
Pedro的模板比我需要的功能多得多,例如,可以列出视频,但编辑模板以满足我的需要非常简单

<xsl:template match="/">
    <html>
        <body>
            …
            <xsl:apply-templates/>
            …
        </body>
    </html>
</xsl:template>

<xsl:template match="sitemap:urlset">
    …
    <xsl:for-each select="sitemap:url">
        …
        <xsl:apply-templates select="xhtml:*"/>
        …
    </xsl:for-each>
    …
</xsl:template>

<xsl:template match="xhtml:link">
    <xsl:variable name="altloc">
        <xsl:value-of select="@href"/>
    </xsl:variable>
    <p>
        Alt language version: 
        <a href="{$altloc}">
            <xsl:value-of select="@href"/> 
        </a> 
        –
        <xsl:if test="@hreflang">
            <xsl:value-of select="@hreflang"/> 
        </xsl:if> 
    </p>
</xsl:template>