Copied to clipboard

Flag this post as spam?

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


  • Craig O'Mahony 364 posts 918 karma points
    Nov 12, 2013 @ 11:17
    Craig O'Mahony
    0

    Build a href in xslt

    Hi folks,

    I'm utterly stumpoed with this one!!

    I'm trying to build up a href in xslt based upon the node of the page and a property of the logged in person. So what I actually want to end up with is something like the following href:

    /members-page.aspx?delidcode=123456

    What I have is:

    <a href="{umbraco.library:NiceUrl(@id)}">
    <xsl:value-of select="@nodeName" />
    </a> 

    Which builds the /members-page.aspx part

    and

    <xsl:param name="delidcode" select="umbraco.library:GetCurrentMember()/delegateid"/>

    Which gives me the 123456 part based upon the logged in member.

    But I have no clue as to how to append them together to form the href. Everything that I've tried gives me syntax erros when I try to save the xslt.

    Could anybody help please?

    Thanks,

    Craig

  • Chriztian Steinmeier 2800 posts 8790 karma points MVP 8x admin c-trib
    Nov 12, 2013 @ 11:40
    Chriztian Steinmeier
    100

    Hi Craig,

    Might be two separate problems here - first one is when you save the XSLT, Umbraco will run the transform using the Content node as $currentPage, so some functions (like the NiceUrl() one) will fail if not guarded against. Sometimes you can work around this by clicking the Skip errors checkbox before saving.

    Second one is how you build the attribute, which you didn't mention - but here's some code to get you started:

    <xsl:variable name="delidcode" select="umbraco.library:GetCurrentMember()/delegateid" />
    
    <xsl:template match="/">
        <!-- Don't do anything if no current member -->
        <xsl:if test="$delidcode">
            <a href="{umbraco.library:NiceUrl($currentPage/@id)}?delidcode={$delidcode}">
                <xsl:value-of select="$currentPage/@nodeName" />
            </a>
        </xsl:if>
    </xsl:template>
    

    /Chriztian

  • Craig O'Mahony 364 posts 918 karma points
    Nov 12, 2013 @ 12:04
    Craig O'Mahony
    0

    Genius! You are a genius!

    Had to amend it slightly as all of the links were for the current page but other than that you were bang on!!

    Final code:<!-- Don't do anything if no current member -->

    <xsl:if test="$delidcode">

    <a href="{umbraco.library:NiceUrl(@id)}?delidcode={$delidcode}">

    <xsl:value-of select="@nodeName" />

    </a>

    </xsl:if>

    Thanks a million!

Please Sign in or register to post replies

Write your reply to:

Draft