MoinLight

moinformat/resources/fixlinks.xsl

315:171156732536
2022-06-03 Paul Boddie Fixed the table of contents macro to handle an absence of section entries.
     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:if test="not(contains(., '#')) or substring-before(., '#')">    57           <xsl:text>/</xsl:text>    58           <xsl:value-of select="$document_index"/>    59         </xsl:if>    60     61         <!-- Add any fragment identifier. -->    62     63         <xsl:if test="contains(., '#')">    64           <xsl:text>#</xsl:text>    65           <xsl:value-of select="substring-after(., '#')"/>    66         </xsl:if>    67       </xsl:attribute>    68     </xsl:when>    69     70     <!-- Preserve links without any document index specified. -->    71     72     <xsl:otherwise>    73       <xsl:copy/>    74     </xsl:otherwise>    75   </xsl:choose>    76 </xsl:template>    77     78 <!-- Copy all other nodes. -->    79     80 <xsl:template match="@*|node()">    81   <xsl:copy>    82     <xsl:apply-templates select="@*|node()"/>    83   </xsl:copy>     84 </xsl:template>    85     86 </xsl:stylesheet>