Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Anthony Candaele 1197 posts 2049 karma points
    Nov 25, 2010 @ 22:12
    Anthony Candaele
    0

    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

  • Thor Madsen-Holm 82 posts 212 karma points c-trib
    Nov 25, 2010 @ 22:20
    Thor Madsen-Holm
    2

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

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Nov 25, 2010 @ 22:30
    Jan Skovgaard
    1

    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

  • Ralph van Vugt 57 posts 101 karma points
    Nov 25, 2010 @ 22:33
    Ralph van Vugt
    0

    Hi Anthony,

    Try to break up the < a href > in parts like this:

    <a>
     <xsl:attribute name="href">
       <xsl:value-of select="$link" />
     </xsl:attribute>
     <xsl:text>name of link</xsl:text>
    </a>

    Edit: typo's.

  • Colin Browne 31 posts 52 karma points
    Nov 29, 2010 @ 16:43
    Colin Browne
    0

    Is there any reason to prefer the long verbose method

     

    <a>
     
    <xsl:attribute name="href">
       
    <xsl:value-of select="$link" />
     
    </xsl:attribute>
     
    <xsl:text>name of link</xsl:text>
    </a>

    <p>

    Instead of the shorter

    <a href="{$link}">link</a>
  • Chriztian Steinmeier 2800 posts 8790 karma points MVP 8x admin c-trib
    Nov 29, 2010 @ 17:01
    Chriztian Steinmeier
    1

    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

  • Kim Andersen 1447 posts 2196 karma points MVP
    Nov 29, 2010 @ 17:02
    Kim Andersen
    1

    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

Please Sign in or register to post replies

Write your reply to:

Draft