Skip to content

Instantly share code, notes, and snippets.

@sirlancelot
Created July 15, 2009 23:54
Show Gist options
  • Save sirlancelot/148066 to your computer and use it in GitHub Desktop.
Save sirlancelot/148066 to your computer and use it in GitHub Desktop.
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<!-- Properly base URLs so they work -->
<xsl:template name="GetUrl" match="@href | @src" mode="html">
<xsl:param name="Url" select="." />
<xsl:variable name="AbsoluteUrl">
<xsl:choose>
<xsl:when test="contains($Url,'://') or starts-with($Url,'/')"><xsl:value-of select="$Url" /></xsl:when>
<xsl:when test="starts-with($Url,'~/')"><xsl:value-of select="concat($root,substring($Url,1))" /></xsl:when>
<xsl:otherwise>
<xsl:value-of select="concat($root,'/',$url-page)" />
<xsl:if test="$url-page != ''">/</xsl:if>
<xsl:value-of select="$Url" />
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:choose>
<xsl:when test="name() = 'href' or name() = 'src'"><xsl:attribute name="{name()}"><xsl:value-of select="$AbsoluteUrl" /></xsl:attribute></xsl:when>
<xsl:otherwise><xsl:value-of select="$AbsoluteUrl" /></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