2016-08-16 53 views
1

我有一個使用xhtml:link標記的Google's specifications for multilingual sitemaps多語言站點的XML站點地圖。Google多語言站點地圖/ xhtml的正確XSLT語法:鏈接

的語法如下:

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

我試圖使這個人類可讀的使用XSLT模板,像這樣的客戶:

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

沒有xhtml:link標籤其中一期工程。但我不確定如何正確引用xhtml:link標籤。我試過這樣的事情:

<xsl:for-each select="xhtml:link"> 
    <tr> 
    <td> 
     <xsl:value-of select="xhtml:[email protected]"/> 
    </td> 
    <td> 
     <xsl:value-of select="xhtml:[email protected]"/> 
    </td> 
    <td colspan="2"></td> 
    </tr> 
</xsl:for-each> 

但這不起作用。

什麼是在Google多語言站點地圖中循環/選擇xhtml:link標記的正確XSLT語法?

回答

1

我無法得到它的識別/使用此代碼引用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> 
0

您已經在xhtml:link節點(在xsl:for-each中)。使用

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

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