Debian Codegraph @

xslt/mallard/html/mal2html-svg.xsl

raw
1 <?xml version='1.0' encoding='UTF-8'?><!-- -*- indent-tabs-mode: nil -*- -->
2 <!--
3 This program is free software; you can redistribute it and/or modify it under
4 the terms of the GNU Lesser General Public License as published by the Free
5 Software Foundation; either version 2 of the License, or (at your option) any
6 later version.
7
8 This program is distributed in the hope that it will be useful, but WITHOUT
9 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
10 FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
11 details.
12
13 You should have received a copy of the GNU Lesser General Public License
14 along with this program; see the file COPYING.LGPL. If not, see <http://www.gnu.org/licenses/>.
15 -->
16
17 <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
18 xmlns:mal="http://projectmallard.org/1.0/"
19 xmlns:svg="http://www.w3.org/2000/svg"
20 xmlns:xlink="http://www.w3.org/1999/xlink"
21 xmlns:exsl="http://exslt.org/common"
22 xmlns="http://www.w3.org/1999/xhtml"
23 exclude-result-prefixes="mal svg xlink"
24 extension-element-prefixes="exsl"
25 version="1.0">
26
27 <!--!!==========================================================================
28 Mallard to HTML - SVG
29 Handle embedded SVG.
30 @revision[version=1.0 date=2010-06-04 status=final]
31
32 This stylesheet matches embedded SVG in {mal2html.block.mode} and processes it
33 in {mal2html.svg.mode}.
34 -->
35
36 <!--%%==========================================================================
37 mal2html.svg.mode
38 Output SVG and handle Mallard extensions.
39 @revision[version=3.18 date=2015-05-04 status=final]
40
41 This mode is used for processing SVG embedded into Mallard documents. For most
42 types of SVG content, it simply copies the input directly, except it outputs
43 the SVG in a way that allows the namespace to stripped for non-XML output. It
44 checks for Mallard linking using the `mal:xref` attribute and transforms this
45 to an XLink `xlink:href` attribute.
46 -->
47 <xsl:template mode="mal2html.svg.mode" match="svg:*">
48 <xsl:choose>
49 <xsl:when test="@mal:xref">
50 <xsl:variable name="target">
51 <xsl:call-template name="mal.link.target">
52 <xsl:with-param name="node" select="."/>
53 <xsl:with-param name="xref" select="@mal:xref"/>
54 </xsl:call-template>
55 </xsl:variable>
56 <xsl:variable name="title">
57 <xsl:call-template name="mal.link.content">
58 <xsl:with-param name="xref" select="@mal:xref"/>
59 <xsl:with-param name="role" select="'text'"/>
60 </xsl:call-template>
61 </xsl:variable>
62 <svg:a xlink:href="{$target}" xlink:title="{$title}">
63 <xsl:element name="{local-name(.)}" namespace="{$html.svg.namespace}">
64 <xsl:for-each select="@*[
65 namespace-uri(.)!='http://projectmallard.org/1.0/' and
66 namespace-uri(.)!='http://www.w3.org/1999/xlink']">
67 <xsl:copy-of select="."/>
68 </xsl:for-each>
69 <xsl:apply-templates mode="mal2html.svg.mode" select="node()"/>
70 </xsl:element>
71 </svg:a>
72 </xsl:when>
73 <xsl:otherwise>
74 <xsl:element name="{local-name(.)}" namespace="{$html.svg.namespace}">
75 <xsl:for-each select="@*[namespace-uri(.)!='http://projectmallard.org/1.0/']">
76 <xsl:copy-of select="."/>
77 </xsl:for-each>
78 <xsl:apply-templates mode="mal2html.svg.mode" select="node()"/>
79 </xsl:element>
80 </xsl:otherwise>
81 </xsl:choose>
82 </xsl:template>
83
84 <xsl:template mode="mal2html.svg.mode" match="text()">
85 <xsl:copy-of select="."/>
86 </xsl:template>
87
88 <xsl:template mode="mal2html.block.mode" match="svg:svg">
89 <xsl:variable name="if"><xsl:call-template name="mal.if.test"/></xsl:variable><xsl:if test="$if != ''">
90 <xsl:variable name="id">
91 <xsl:choose>
92 <xsl:when test="@xml:id">
93 <xsl:value-of select="@xml:id"/>
94 </xsl:when>
95 <xsl:when test="@id">
96 <xsl:value-of select="@id"/>
97 </xsl:when>
98 <xsl:otherwise>
99 <xsl:value-of select="generate-id(.)"/>
100 </xsl:otherwise>
101 </xsl:choose>
102 </xsl:variable>
103 <div>
104 <xsl:call-template name="html.class.attr">
105 <xsl:with-param name="class">
106 <xsl:text>svg</xsl:text>
107 <xsl:if test="$if != 'true'">
108 <xsl:text> if-if </xsl:text>
109 <xsl:value-of select="$if"/>
110 </xsl:if>
111 </xsl:with-param>
112 </xsl:call-template>
113 <xsl:apply-templates mode="mal2html.svg.mode" select="."/>
114 </div>
115 </xsl:if>
116 </xsl:template>
117
118 </xsl:stylesheet>