The verbose method exists so you can create attributes where the name depends on something else (or is in a variable); Or when you need to decide if some condition is met before you add it.
There is an <xsl:element> instruction to do the same with elements.
In some cases there can be reasons to use the longer version with <xsl:attribute>. But if you already have got the entire link in a variable and just want to insert it in the href attribute I can't see a reason to not use the simple one-line-method.
But sometimes you migh have the need to build up the link inside the <xsl:attribute>-element, or create different scenarios in there etc. etc. In those cases the "long" version is often the easiest/best way. But actually, in the end, it's up the person who write the code what they prefer.
formatting an <a> element in Xslt
Hi,
I created a Widget-macro whereby a user can insert a url.
In the Xslt file I try to format a <a> element like this:
<p><a href="<xsl:value-of select="$link"/>"link</a></p>
but obviously this does not work because '<xsl:value-of select=' is interpreted as a text string and not as Xslt code.
Thanks for your help,
Anthony Candaele
Belgium
Hi Anthony,
Try this:
<p>
<a href="{$link}">link</a>
</p>
I assume that $link is an <xsl:variable> ?
Otherwise what this could be what you are looking for:
<p>
<a her="{$currentPage/link}">link</a>
</p>
Hopes this can help you get a little further :-)
You could also add the link like this
<a>
<xsl:attribute name="href"><xsl:value-of select="$link" /></xsl:attribute>
<xsl:text>Link</xsl:text>
</a>
As Thor I'm also asuming that you have the link in a variable...
but otherwise you should be able to get the link using umbraco.library:NiceUrl($currentPage/@id) - replace that with $link if needed.
/Jan
Hi Anthony,
Try to break up the < a href > in parts like this:
Edit: typo's.
Is there any reason to prefer the long verbose method
Instead of the shorter
<a href="{$link}">link</a>Hi Colin,
The verbose method exists so you can create attributes where the name depends on something else (or is in a variable); Or when you need to decide if some condition is met before you add it.
There is an <xsl:element> instruction to do the same with elements.
/Chriztian
Hi Colin
In some cases there can be reasons to use the longer version with <xsl:attribute>. But if you already have got the entire link in a variable and just want to insert it in the href attribute I can't see a reason to not use the simple one-line-method.
But sometimes you migh have the need to build up the link inside the <xsl:attribute>-element, or create different scenarios in there etc. etc. In those cases the "long" version is often the easiest/best way. But actually, in the end, it's up the person who write the code what they prefer.
/Kim A
is working on a reply...
This forum is in read-only mode while we transition to the new forum.
You can continue this topic on the new forum by tapping the "Continue discussion" link below.