Copied to clipboard

Flag this post as spam?

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


  • Bo Damgaard Mortensen 719 posts 1207 karma points
    Feb 14, 2011 @ 14:49
    Bo Damgaard Mortensen
    0

    Strange URL behavior

    Hi all,

    I'm having a bit of trouble trying to extract a url from a member and use it as a link in XSLT.

    My scenario is: each Member has got a property of the type textstring to hold their url to their website. When I try to get hold of this in XSLT and use it as a regular link, the link looks like this on the frontend:

    http://www.mysite.com/http://www.theMemberUrlString.com/

    So basically it tries to find "http://www.theMemberUrlstring.com on my website. When I try to get the value-of my memberUrl variable it displays correctly - also if I use copy-of instead.

    My XSLT looks like this:

    <xsl:variable name="memberId" select="umbraco.library:GetRelatedNodesAsXml(current()/@id)/relations/relation[@typeId = 5]" />
                  <xsl:variable name="member" select="umbraco.library:GetMember($memberId/@parentId)" />
                  <xsl:variable name="memberUrl" select="string($member//hjemmeside)" />

                  <a href="{$memberUrl}" target="_blank">thelink</a>

    .. where $member//hjemmeside is the textstring property on the member that holds the url.

    Anyone know of a 'hotfix' to this problem? :) Any help is greatly appreciated!

    All the best,

    Bo

  • Tim 1193 posts 2675 karma points MVP 4x c-trib
    Feb 14, 2011 @ 17:41
    Tim
    0

    It might be because the {} syntax url encodes the value (just guessing)?

    If you change the code slightly like this:

    <a target="_blank">
      <xsl:attribute>
        <xsl:value-of select="$memberUrl">
      </xsl:attribute>
      <xsl:text>thelink</xsl:text>

    </a>

    Does it work ok?

  • Tim 1193 posts 2675 karma points MVP 4x c-trib
    Feb 14, 2011 @ 17:43
    Tim
    0

    <xsl:attribute> should be <xsl:attribute name="href">, sorry!

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Feb 14, 2011 @ 18:32
    Jan Skovgaard
    0

    Hi Bo and Tim

    I don't think that using the xsl:attribute element will solve this problem. As far as I can tell it would output the same but of course it's worth the try.

    @Bo: what format do you insert the url in? is it like http://www.yourmemberurl.com or just yourmemberurl.com? Have you tried to just use www.memberurl.com? And what happens if you just write <xsl:value-of select="$memberUrl" /> ?

    /Jan

  • Bo Damgaard Mortensen 719 posts 1207 karma points
    Feb 14, 2011 @ 21:16
    Bo Damgaard Mortensen
    1

    Tim: thanks a lot for your help, but it wasn't the issue here :) Although you're right, I think it's best practice to output links like you described!

    However, Jan is right here - it depends on if "http://" is included in the url string or not. If it isn't included, it will link to: http://www.yoursite.com/www.theUrl.com

    So basically this little choose snippet here saved the day (or night, mayhaps? ;))

                  <xsl:variable name="member" select="umbraco.library:GetMember($memberId/@parentId)" />
                  <xsl:variable name="memberUrl" select="string($member//hjemmeside)" />

                  <a target="_blank">
                    <xsl:attribute name="href">
                      <xsl:choose>
                        <xsl:when test="contains($memberUrl, 'http://')">
                          <xsl:value-of select="$memberUrl" />
                        </xsl:when>
                        <xsl:otherwise>
                          <xsl:text>http://</xsl:text><xsl:value-of select="$memberUrl" />
                        </xsl:otherwise>
                      </xsl:choose>
                    </xsl:attribute>

    Again, thanks for the help! :)

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Feb 14, 2011 @ 21:48
    Jan Skovgaard
    0

    Hi Bo

    I think that it's a matter of preference how to pass the value to the href attribute. Using the xsl:attribute method is indeed nice when one needs to manipulate the href value dependent on certain cases etc one needs to test for.

    Happy to see you got it solved. This is something that can be very annoying and confusing when working with Umbraco :-)

    /Jan

Please Sign in or register to post replies

Write your reply to:

Draft