Copied to clipboard

Flag this post as spam?

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


  • Bjarne Fyrstenborg 1182 posts 3441 karma points MVP 4x c-trib
    Dec 08, 2011 @ 22:26
    Bjarne Fyrstenborg
    0

    Replace text with a link

    Hi..

    How can I replace a string with a link in xslt?
    E.g. if the string contains www or http:// it should make it to a link..

    but there is probably no way to change the link text to something else without writing the full html code or use a datatype which allow inserting of links..

    Bjarne

  • Kim Andersen 1447 posts 2196 karma points MVP
    Dec 08, 2011 @ 22:44
    Kim Andersen
    2

    Hi Bjarne

    Let's say that the text is placed in a variable called $text.Then something like this should do the trick:

    <xsl:choose>
    <xsl:when test="contains($text,'http://') or contains($text,'www')">
    <a href="{$text}">Click me!</a>
    </xsl:when>
    <xsl:otherwise>
    <xsl:value-of select="$text" />
    </xsl:otherwise>
    </xsl:choose>

    I hope that helps :)

    /Kim A

  • Bjarne Fyrstenborg 1182 posts 3441 karma points MVP 4x c-trib
    Dec 08, 2011 @ 23:09
    Bjarne Fyrstenborg
    0

    Hi Kim

    Thanks for your feedback :)
    I expiment with the Tabular Data package in some product specifications.. where I want to include a link to the producent website.

    With your help it works now: http://sub.ak-security.dk/da/shop/lygter/led-lenser-p7.aspx

    ....
    <
    td>
    <xsl:choose>
            <xsl:when test="contains(./Cell,'http://') or contains(./Cell,'www')">
                            <href="{./Cell}" target="_blank">Klik her</a>
                    </xsl:when>
                    <xsl:otherwise>
                            <xsl:value-of select="./Cell" disable-output-escaping="yes"/>
            </xsl:otherwise>
    </xsl:choose>
    </td>
    .... 

    Bjarne

  • Kim Andersen 1447 posts 2196 karma points MVP
    Dec 09, 2011 @ 17:27
    Kim Andersen
    0

    Cool, great to hear that Bjarne.

    I'm glad I could help :)

    /Kim Andersen

  • Bjarne Fyrstenborg 1182 posts 3441 karma points MVP 4x c-trib
    Dec 09, 2011 @ 18:59
    Bjarne Fyrstenborg
    0

    Hi Kim

    This require more to work, but can I do a test on the string, so it not takes all words, e.g. if I write in the datatype table cell: Here is a link to www.google.com .. so it's only www.google.com which will be a link..?

    it's not the most important thing, but it would be nice to have the possibility to include other words... perhaps something like it should start the link where www og http:// starts and then end the link after a space..

    Right now I only have a link here: http://sub.ak-security.dk/da/shop/lygter/led-lenser-p7.aspx under the Specifikationer tab to the manufacturer.

    Bjarne

  • 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