tags:

views:

28

answers:

3

Hi

I have some XML data which includes URIs. I want to list the URIs on an ASP page, but also to make them clickable using <a> tags. However XSLT does not allow you to embed an XSL command within a tag, eg:

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

How can I include the URL in the <uri> tag after the <a href=" code?

+6  A: 

Use the <xsl:attribute> element to have non-fixed attribute.

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

Edit: As others have mentioned, it is also possible to use attribute value templates:

<a href="{.}" alt="More information" target="_blank">
  <xsl:value-of select="." />
</a>
KennyTM
Fantastic - many thanks.
Nick
+3  A: 

In addition to using <xsl:attribute> (mentioned in KennyTM's answer) it is also possible to use the "{}" shorthand notation when working with attributes:

<a href="{.}"><xsl:value-of select="." /></a>
pafcu
Also very useful to know. Cheers.
Nick
+3  A: 

Use:

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

Try to use AVTs (Attribute-Value-Templates) whenever possible (on all attributes except a select attribute). This makes the code shorter and much more readable.

Dimitre Novatchev