将XSL代码嵌入<a>标记中

Nic*_*ckM 7 xml xslt

我有一些包含URI的XML数据.我想列出ASP页面上的URI,还要使用<a>标签使它们可点击.但是,XSLT不允许您在标记中嵌入XSL命令,例如:

<xsl:for-each select="//uri">
  <tr>
    <td class="tdDetail">
      More information
    </td>
    <td>
      <a href="<xsl:value-of select="." />" alt="More information" target=_blank><xsl:value-of select="." /></a>
    </td>
  </tr>
</xsl:for-each>
Run Code Online (Sandbox Code Playgroud)

如何在<uri>代码后的标记中包含URL <a href="

ken*_*ytm 11

使用<xsl:attribute>元素有非固定属性.

<a alt="More information" target="_blank">
  <xsl:attribute name="href">
    <xsl:value-of select="." />
  </xsl:attribute>
  <xsl:value-of select="." />
</a>
Run Code Online (Sandbox Code Playgroud)

编辑:正如其他人所提到的,也可以使用属性值模板:

<a href="{.}" alt="More information" target="_blank">
  <xsl:value-of select="." />
</a>
Run Code Online (Sandbox Code Playgroud)


Dim*_*hev 5

用途:

<a href="{.}" alt="More information" target="_blank"> 
  <xsl:value-of select="." /> 
</a>
Run Code Online (Sandbox Code Playgroud)

尝试使用AVTS(属性-值模板)只要有可能(在所有的属性,除了一个select属性).这使代码更短,更易读.