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