0 users online. Create an account or sign in to join them.Users

Release Date:
6 Jan 2013
Date & Time


Super simple way (read: rudimentary) to convert plain text strings that contain http:// or https:// URLs into clickable HTML hyperlinks, expanded on code originally from this thread - http://www.stylusstudio.com/xsllist/200305/post81170.html

Could probably do with some Regex instead of matching "http://" or "https://", but its was not necessary for my use.


View Raw
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<!-- Converts any number of plain text URL strings into HTML formatted hyperlinks in a passage of text -->
<!-- Made by @george_wilson January 2013, updated December 2013 -->

<xsl:template name="hyperlink">
      <xsl:param name="string" select="string()" />

      <xsl:variable name="http">
          <xsl:when test="contains($string, 'http://')">
          </xsl:when><xsl:when test="contains($string, 'https://')">

        <xsl:when test="$http = 'false'">
          <!-- No links, output string -->
          <xsl:value-of select="$string"/>
          <!-- Links detected, replace them -->

          <!-- Set up variables -->
          <xsl:variable name="before" select="substring-before($string, $http)" />
          <xsl:variable name="after" select="substring-after($string, $http)" />
          <xsl:variable name="url" select="concat($http, substring-before($after,' '))"/>
          <xsl:variable name="rest" select="substring-after($string, $url)" />

          <!-- Output the text -->
          <xsl:value-of select="$before"/>

            <!-- If the url is at then end, $rest doesn't work -->
            <xsl:when test="substring-after($url,$http) != ''">
              <a href="{$url}" rel="nofollow">
                <xsl:value-of select="$url" />
              <!-- Check the remainder for links -->
              <xsl:call-template name="hyperlink">
                <xsl:with-param name="string" select="$rest"/>
              <a href="{$url}{$after}" rel="nofollow">
                <xsl:value-of select="$after" />



Discuss this XSLT Utility

Symphony • Open Source XSLT CMS

Server Requirements

  • PHP 5.3-5.6 or 7.0-7.3
  • PHP's LibXML module, with the XSLT extension enabled (--with-xsl)
  • MySQL 5.5 or above
  • An Apache or Litespeed webserver
  • Apache's mod_rewrite module or equivalent

Compatible Hosts

Sign in

Login details