Copied to clipboard

Flag this post as spam?

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


  • Dinesh 13 posts 33 karma points
    Sep 19, 2011 @ 22:28
    Dinesh
    0

    Getting value of External Link

    Hi,

    I have a property with alias name externalLink. I just want to get it's value in href of anchor tag when its present. This is what I have got so far. But it never gives me the value of externalLink even if it's present.

    <xsl:template match="/">

    <xsl:for-each select="$currentPage/ancestor-or-self::* [@level=$level]/* [@isDoc and string(umbracoNaviHide) != '1']">
      <div class="Nav2">
        <a href="{umbraco.library:NiceUrl(@id)}">
          <xsl:if test="data[@alias='externalLink']!= ''">
            <xsl:attribute name="href">
              <xsl:value-of select="data[@alias='externalLink']"/>
            </xsl:attribute>  
          </xsl:if>
          <xsl:value-of select="navTitle"/>
        </a>
      </div>
    </xsl:for-each>

    </xsl:template>

     

    Any help will be appreciated.

    Thanks

    D

  • Tom Fulton 2030 posts 4996 karma points c-trib
    Sep 19, 2011 @ 22:38
    Tom Fulton
    1

    Hi,

    It looks like you are mixing the new and old schemas.  Try replacing "data [@alias='externalLink']" with just "externalLink", ie:

          <xsl:if test="externalLink!= ''">
            <xsl:attribute name="href">
              <xsl:value-of select="externalLink"/>
            </xsl:attribute>  
          </xsl:if>

    For more info:  our.umbraco.org/wiki/reference/xslt/45-xml-schema

    -Tom

  • Chriztian Steinmeier 2726 posts 8320 karma points MVP 4x admin c-trib
    Sep 19, 2011 @ 22:39
    Chriztian Steinmeier
    1

    Hi Dinesh,

    You're actually doing it right, but the snippet you grabbed for the attribute thing uses the old XML schema (search for it if you want to know about it) - here's how that sample would look:

    <div class="Nav2">
        <a href="{umbraco.library:NiceUrl(@id)}">
            <xsl:if test="normalize-space(externalLink)">
                <xsl:attribute name="href">
                    <xsl:value-of select="externalLink"/>
                </xsl:attribute>   
            </xsl:if>
            <xsl:value-of select="navTitle"/>
        </a>
    </div>
    

    I, however, prefer a slightly different approach, using a match template:

    <xsl:template match="/">
    ...
        <div class="Nav2">
            <a href="{umbraco.library:NiceUrl(@id)}">
                <xsl:apply-templates select="externalLink[normalize-space()]" />
                <xsl:value-of select="navTitle"/>
            </a>
        </div>
    ...
    </xsl:template>
    
    
    <xsl:template match="externalLink">
        <xsl:attribute name="href">
            <xsl:value-of select="."/>
        </xsl:attribute>
    </xsl:template>

    /Chriztian

  • Chriztian Steinmeier 2726 posts 8320 karma points MVP 4x admin c-trib
    Sep 19, 2011 @ 22:40
    Chriztian Steinmeier
    0

    Snappy, Tom! :-)

  • Dinesh 13 posts 33 karma points
    Sep 20, 2011 @ 17:00
    Dinesh
    0

    Tom & Chriztian,

    Thanks a lot guys. I am just catching up with XSLT. It works like a charm with your suggestions.

    -Dinesh

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

Please Sign in or register to post replies