我有以下XML。我自己添加了xhtml:link
。
<url>
<loc>https://sitename/choix-entrepreneur/12-questions-a-poser-a-votre-entrepreneur/</loc>
<lastmod>2017-09-01T21:06:07+05:00</lastmod>
<image:image>
<image:loc>https://sitename/wp-content/uploads/2017/09/questions-aux-entrepreneurs-non-verifies-par-reno-assistance-1.jpg</image:loc>
<image:title><!--[CDATA[questions-aux-entrepreneurs-non-verifies-par-reno-assistance]]--></image:title>
<image:caption><!--[CDATA[questions-aux-entrepreneurs-non-verifies-par-reno-assistance]]--></image:caption>
</image:image>
<image:image>
<image:loc>http://sitename/wp-content/uploads/2014/11/360verification_fr.png</image:loc>
<image:caption><!--[CDATA[Rapport de vérification à 360° dans l'écran d'un ordinateur]]--></image:caption>
</image:image>
<image:image>
<image:loc>http://sitename/wp-content/uploads/2017/08/calendrier-entrepreneur.jpg</image:loc>
<image:caption><!--[CDATA[Agenda d'un entrepreneur en construction ou rénovation]]--></image:caption>
</image:image>
<image:image>
<image:loc>http://sitename/wp-content/uploads/2017/08/famille-deplace-sofa-avant-renovations.jpg</image:loc>
<image:caption><!--[CDATA[Couple déménageant un sofa]]--></image:caption>
</image:image>
<image:image>
<image:loc>http://sitename/wp-content/uploads/2017/08/homme-regardant-telephone.jpg</image:loc>
<image:caption><!--[CDATA[Homme regardant son téléphone intelligent]]--></image:caption>
</image:image>
<image:image>
<image:loc>http://sitename/wp-content/uploads/2017/08/conteneur-a-dechet-construction-blogue.jpg</image:loc>
<image:caption><!--[CDATA[Conteneur à déchet de construction]]--></image:caption>
</image:image>
<xhtml:link rel="alternate" hreflang="en" href="https://sitename/en/?p=102151"></xhtml:link>
现在,对于此XML,我们正在XSLT中对其进行处理。但是我无法处理HTML中的xhtml:link
。我不知道该如何选择。我有以下代码可以做到这一点。帮助将不胜感激..
<td>
<xsl:variable name="hrefLANG">
<xsl:value-of select="sitemap:[@rel='alternate']/@href"/>
</xsl:variable>
<a href="{$hrefLANG}">
<xsl:value-of select="sitemap:[@rel='alternate']/@href"/>
</a>
</td>
答案 0 :(得分:0)
有两种方法:
您可以在自己的计算机中定义XHTML名称空间http://www.w3.org/1999/xhtml
通过{p>在您的<xsl:stylesheet ...
元素上进行XSLT
xmlns:xhtml="http://www.w3.org/1999/xhtml">
然后使用
进行访问<xsl:variable name="hrefLANG">
<xsl:value-of select="//xhtml:link[@rel='alternate']/@href"/>
</xsl:variable>
<xsl:element name="a">
<xsl:attribute name="href">
<xsl:value-of select="$hrefLANG"/>
</xsl:attribute>
</xsl:element>
使用xsl:element
构造元素以摆脱输出中的名称空间
您可以忽略名称空间-虽然名称空间不够精确,但也可以使用
<xsl:variable name="hrefLANG">
<xsl:value-of select="//*[local-name()='link'][@rel='alternate']/@href"/>
</xsl:variable>
<xsl:element name="a">
<xsl:attribute name="href">
<xsl:value-of select="$hrefLANG"/>
</xsl:attribute>
</xsl:element>
两种情况下的输出均为
<a href="https://sitename.com/en/?p=102151"/>