获取有多个链接标签时具有特定rel的链接标签的xsl value-of href属性



我有一个xml文件,它有多个名为tag1的标签,每个条目标签有多个链接标签,我需要链接标签的href,其rel="x">

<tag1>
<id>1</id>
<timestamp>2023-04-03T07:36:54.100Z</timestamp>
<updated>2023-04-03T07:36:54.100Z</updated>
<link href="https://the-link-i-need" rel="x-icon" />
<link href="https://another-link" rel="y" />
</tag1>

我试过这个,但是它给了我所有的链接"tag1"而iconLink每次只给出first tag1的first link标签的第一个href。

<xsl:for-each select="tag1">
<div >                            
<xsl:for-each select="//link[contains(@rel, 'icon')]">
<p>
Link: <xsl:value-of select="@href"/>
</p>
</xsl:for-each>
<xsl:value-of select="//link[contains(@rel, 'icon')]/@href"/>
<xsl:variable name="iconLink" select="//link[contains(@rel,'icon')]/@href" />
<div>
<xsl:if test="$iconLink">
<img src="{$iconLink}" alt="icon" />
</xsl:if>
</div>                            

</div>
</xsl:for-each>

外部<xsl:for-each select="tag1">将上下文节点更改为tag1元素,内部使用的任何路径都应相对于该元素,因此选择link子元素时不要使用//link,而只需使用link

最新更新