1 <?xml version="1.0" ?> 2 3 <!-- 4 Fix links, adding the index document filename if appropriate. 5 6 Copyright (c) 2019 Paul Boddie <paul@boddie.org.uk> 7 8 This program is free software; you can redistribute it and/or modify it under 9 the terms of the GNU General Public License as published by the Free Software 10 Foundation; either version 3 of the License, or (at your option) any later 11 version. 12 13 This program is distributed in the hope that it will be useful, but WITHOUT 14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 15 FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 16 details. 17 18 You should have received a copy of the GNU General Public License along with 19 this program. If not, see <http://www.gnu.org/licenses/>. 20 --> 21 22 <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0" 23 xmlns:svg="http://www.w3.org/2000/svg" 24 xmlns:xlink="http://www.w3.org/1999/xlink"> 25 <xsl:output method="xml" indent="yes" 26 doctype-public="-//W3C//DTD SVG 1.0//EN" 27 doctype-system="http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd"/> 28 29 <!-- Accept the document index as a stylesheet parameter. --> 30 31 <xsl:param name="document_index"/> 32 33 <!-- Process link attributes only. --> 34 35 <xsl:template match="@xlink:href"> 36 <xsl:choose> 37 38 <!-- Append the document index to the current value. --> 39 40 <xsl:when test="$document_index"> 41 <xsl:attribute name="xlink:href"> 42 43 <!-- Generate the target resource. --> 44 45 <xsl:choose> 46 <xsl:when test="contains(., '#')"> 47 <xsl:value-of select="substring-before(., '#')"/> 48 </xsl:when> 49 <xsl:otherwise> 50 <xsl:value-of select="."/> 51 </xsl:otherwise> 52 </xsl:choose> 53 54 <!-- Add a path separator and document index. --> 55 56 <xsl:text>/</xsl:text> 57 <xsl:value-of select="$document_index"/> 58 59 <!-- Add any fragment identifier. --> 60 61 <xsl:if test="contains(., '#')"> 62 <xsl:text>#</xsl:text> 63 <xsl:value-of select="substring-after(., '#')"/> 64 </xsl:if> 65 </xsl:attribute> 66 </xsl:when> 67 68 <!-- Preserve links without any document index specified. --> 69 70 <xsl:otherwise> 71 <xsl:copy/> 72 </xsl:otherwise> 73 </xsl:choose> 74 </xsl:template> 75 76 <!-- Copy all other nodes. --> 77 78 <xsl:template match="@*|node()"> 79 <xsl:copy> 80 <xsl:apply-templates select="@*|node()"/> 81 </xsl:copy> 82 </xsl:template> 83 84 </xsl:stylesheet>