2010-08-19 9 views
6

Ho alcuni dati XML che includono URI. Voglio elencare gli URI in una pagina ASP, ma anche renderli selezionabili usando i tag <a>. Tuttavia XSLT non consente di incorporare un comando XSL all'interno di un tag, ad esempio:Incorporamento del codice XSL all'interno di un tag <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> 

Come posso includere l'URL nel tag <uri> dopo il codice <a href="?

risposta

11

Utilizzare the <xsl:attribute> element per attribuire un attributo non fisso.

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

Edit: Come altri hanno già detto, è anche possibile utilizzare attribute value templates:

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

Fantastico - molte grazie. – NickM

4

Oltre a utilizzare < xsl: attribute> (menzionato nella risposta di KennyTM) è è anche possibile utilizzare la notazione abbreviata "{}" quando si lavora con attributi:

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

Anche molto utile da sapere. Saluti. – NickM

5

Uso:

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

Provare a usare AVTS (attributo-valore-Templates) quando possibile (su tutti gli attributi ad eccezione di un attributo select). Ciò rende il codice più breve e molto più leggibile.

Problemi correlati