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

问题描述 投票:0回答:0

我有一个 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 每次都只给出第一个 tag1 的第一个链接标签的第一个 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>
xml xslt xml-parsing xslt-1.0 xslt-2.0
© www.soinside.com 2019 - 2024. All rights reserved.