Author:
sirlancelot
Version:
1.0
Release Date:
10 Jul 2009
Category:
String Operations

Description

To go along with the HTML Manipulation utility, this template will search hyperlinks and image links for relative URLs and prepend $root to it.

Discuss this utility

XSLT

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

<!-- Default HTML Manipulation. Do not change these -->
<xsl:template match="*" mode="html">
	<xsl:element name="{name()}">
		<xsl:apply-templates select="* | @* | text()" mode="html"/>
	</xsl:element>
</xsl:template>
<xsl:template match="@*" mode="html">
	<xsl:attribute name="{name()}">
		<xsl:value-of select="."/>
	</xsl:attribute>
</xsl:template>



<!-- Format Relative URLs -->
<xsl:template match="@href | @src" mode="html">
    <xsl:attribute name="{name()}">
        <xsl:choose>
            <xsl:when test="contains(.,'://') or starts-with(.,'/')"><xsl:value-of select="." /></xsl:when>
            <xsl:when test="starts-with(.,'~/')"><xsl:value-of select="concat($root,substring(.,1))" /></xsl:when>
            <xsl:otherwise><xsl:value-of select="concat($root,$parent-path,'/',$current-page,'/',.)" /></xsl:otherwise>
        </xsl:choose>
    </xsl:attribute>
</xsl:template>

</xsl:stylesheet>

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