2010-08-19 101 views
6

我有一些XML数据,其中包括URI。我想列出一个ASP页面上的URI,但也可以使用<a>标签使它们可点击。然而XSLT不允许标签中嵌入一个XSL指令,如:嵌入XSL代码<a>标签

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

我怎么能包括<a href="代码后的<uri>代码的网址?

回答

11

使用the <xsl:attribute> element具有非固定属性。

<a alt="More information" target="_blank"> 
    <xsl:attribute name="href"> 
    <xsl:value-of select="." /> 
    </xsl:attribute> 
    <xsl:value-of select="." /> 
</a> 

编辑:正如其他人所提到的,也可以使用attribute value templates

<a href="{.}" alt="More information" target="_blank"> 
    <xsl:value-of select="." /> 
</a> 
+0

太棒了 - 非常感谢。 – NickM 2010-08-19 13:25:12

4

除了使用<的xsl:属性>(在KennyTM的答复中提到),它使用属性时也可以使用“{}”简写符号:

<a href="{.}"><xsl:value-of select="." /></a> 
+0

也很有用的知道。干杯。 – NickM 2010-08-19 13:25:47

5

使用

<a href="{.}" alt="More information" target="_blank"> 
    <xsl:value-of select="." /> 
</a> 

尝试使用AVTS(属性 - 值模板)尽可能(除了上一个select属性的所有属性)。这使得代码更短,更可读。