2010-08-19 96 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屬性的所有屬性)。這使得代碼更短,更可讀。