Created
May 10, 2012 14:40
-
-
Save xpathr/2653506 to your computer and use it in GitHub Desktop.
Format relative URLs by sirlancelot
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"> | |
| <!-- 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> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment