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 18, 2011 @ 17:27
    Bo Damgaard Mortensen
    0

    Converting links

    Hi all,

    I'm currently trying to parse through the bodyText of a document with several [link]http://www.youtube.com[/link] can occur. These should be "transformed" into regular links like: <a href="http://www.youtube.com" target="_blank">http://www.youtube.com</a>;

    So far I have this XSLT:

    <ul>
    <xsl:for-each select="$currentPage/* [name() = $documentTypeAlias and string(umbracoNaviHide) != '1']">
      <li>
        <xsl:if test="contains(current()/bodyText, '[link]')">
          <xsl:variable name="url">
            <xsl:variable name="startUrl" select="substring-after(current()/bodyText, '[link]')" />
            <xsl:variable name="endUrl" select="substring-before($startUrl, '[/link]')" />
            <xsl:value-of select="$endUrl" />
          </xsl:variable>
          
          <xsl:value-of select="$url" />
        </xsl:if>
      </li>
    </xsl:for-each>
    </ul>

    While it gets the link just fine, it only takes the first [link][/link] in the bodyText, and basically skips all the others (if there's more than one [link][/link] in the bodyText) 

    Is there a better way to do this? :-) The [link][/link] thing is required because it's written from a mobilephone that can't handle regular links (don't ask me why!)

    Any XSLT gurus out there that can shed some light on this?

    Thanks in advance!

    All the best,

    Bo

  • Chriztian Steinmeier 2800 posts 8790 karma points MVP 8x admin c-trib
    Feb 18, 2011 @ 18:35
    Chriztian Steinmeier
    1

    Hi Bo,

    Take a look at the Replace() extension function in the umbraco.library namespace. If you want to do this with XSLT you need to google for "recursive templates" to see how you'd do something like this.

    /Chriztian

  • Bo Damgaard Mortensen 719 posts 1207 karma points
    Feb 18, 2011 @ 18:54
    Bo Damgaard Mortensen
    1

    Chriztian,

    A recursive remplate solved it! :-) Thanks a lot !

  • Chriztian Steinmeier 2800 posts 8790 karma points MVP 8x admin c-trib
    Feb 18, 2011 @ 19:58
    Chriztian Steinmeier
    0

    Excellent! That's exactly what I like to hear :-) 

    /Chriztian

Please Sign in or register to post replies

Write your reply to:

Draft