Last active
December 14, 2015 05:59
-
-
Save g-wilson/5039122 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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 2012 with help from this thread - http://www.stylusstudio.com/xsllist/200305/post81170.html --> | |
<xsl:template name="hyperlink"> | |
<xsl:param name="string" select="string()" /> | |
<!-- Set up variables --> | |
<xsl:choose> | |
<xsl:when test="contains($string, 'http://')"> | |
<xsl:variable name="http" select="http://" /> | |
</xsl:when> | |
<xsl:when test="contains($string, 'https://')"> | |
<xsl:variable name="http" select="https://" /> | |
</xsl:when> | |
</xsl:choose> | |
<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"/> | |
<xsl:choose> | |
<!-- If the url is at then end, $rest doesn't work --> | |
<xsl:when test="substring-after($url,$http) != ''"> | |
<a href="{$url}"> | |
<xsl:value-of select="$url" /> | |
</a> | |
<xsl:call-template name="hyperlink"> | |
<xsl:with-param name="string" select="$rest"/> | |
</xsl:call-template> | |
</xsl:when> | |
<xsl:otherwise> | |
<a href="{$url}{$after}"> | |
<xsl:value-of select="$after" /> | |
</a> | |
</xsl:otherwise> | |
</xsl:choose> | |
</xsl:template> | |
</xsl:stylesheet> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I'm trying to import this handy utility in one of my Symphony installations, but I'm getting some error messages:
Invalid expression
(line 13) XSLT-variable: Failed to compile the XPath expression 'http://'.
Invalid expression
(line 16) XSLT-variable: Failed to compile the XPath expression 'https://'.
Don't know if I'm overseeing something? Hope you can push me in the right direction.