Debian Codegraph @

xslt/mallard/html/mal2html-math.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:mml="http://www.w3.org/1998/Math/MathML"
20 xmlns:xlink="http://www.w3.org/1999/xlink"
21 xmlns="http://www.w3.org/1999/xhtml"
22 exclude-result-prefixes="mal mml xlink"
23 version="1.0">
24
25 <!--!!==========================================================================
26 Mallard to HTML - MathML
27 Handle MathML in Mallard documents.
28 @revision[version=3.8 date=2012-11-13 status=final]
29
30 This stylesheet matches embedded MathML in {mal2html.block.mode} and
31 {mal2html.inline.mode} and processes it in {mal2html.math.mode}. The
32 matched templates for the `mml:math` element automatically set the
33 `display` attribute based on whether the element is in block or inline
34 context.
35 -->
36
37
38 <!--%%==========================================================================
39 mal2html.math.mode
40 Output MathML and handle Mallard extensions.
41 @revision[version=3.8 date=2012-11-13 status=final]
42
43 This mode is used for processing MathML embedded into Mallard documents. For
44 most types of MathML content, it simply copies the input directly, except it
45 outputs the MathML in a way that allows the namespace to stripped for non-XML
46 output. It checks for Mallard linking using the `mal:xref` attribute and
47 transforms this to a MathML `href` attribute. It also converts `xlink:href`
48 attributes from MathML 2 to `href` attributes for MathML 3.
49 -->
50 <xsl:template mode="mal2html.math.mode" match="mml:*">
51 <xsl:element name="{local-name(.)}" namespace="{$html.mathml.namespace}">
52 <xsl:for-each select="@*[name(.) != 'href']">
53 <xsl:copy-of select="."/>
54 </xsl:for-each>
55 <xsl:choose>
56 <xsl:when test="@mal:xref">
57 <xsl:attribute name="href">
58 <xsl:call-template name="mal.link.target">
59 <xsl:with-param name="node" select="."/>
60 <xsl:with-param name="xref" select="@mal:xref"/>
61 </xsl:call-template>
62 </xsl:attribute>
63 </xsl:when>
64 <xsl:when test="@href">
65 <xsl:copy-of select="@href"/>
66 </xsl:when>
67 <xsl:when test="@xlink:href">
68 <xsl:attribute name="href">
69 <xsl:value-of select="@xlink:href"/>
70 </xsl:attribute>
71 </xsl:when>
72 </xsl:choose>
73 <xsl:apply-templates mode="mal2html.math.mode"/>
74 </xsl:element>
75 </xsl:template>
76
77 <xsl:template mode="mal2html.math.mode" match="text()">
78 <xsl:value-of select="."/>
79 </xsl:template>
80
81 <xsl:template mode="mal2html.math.mode" match="*"/>
82
83 <xsl:template mode="mal2html.block.mode" match="mml:math">
84 <xsl:variable name="if"><xsl:call-template name="mal.if.test"/></xsl:variable><xsl:if test="$if != ''">
85 <div>
86 <xsl:call-template name="html.lang.attrs"/>
87 <xsl:attribute name="class">
88 <xsl:text>math</xsl:text>
89 <xsl:if test="$if != 'true'">
90 <xsl:text> if-if </xsl:text>
91 <xsl:value-of select="$if"/>
92 </xsl:if>
93 </xsl:attribute>
94 <xsl:element name="math" namespace="{$html.mathml.namespace}">
95 <xsl:for-each select="@*[name(.) != 'display']
96 [not(starts-with(namespace-uri(.), 'http://projectmallard.org/'))]">
97 <xsl:copy-of select="."/>
98 </xsl:for-each>
99 <xsl:attribute name="display">
100 <xsl:value-of select="'block'"/>
101 </xsl:attribute>
102 <xsl:apply-templates mode="mal2html.math.mode"/>
103 </xsl:element>
104 </div>
105 </xsl:if>
106 </xsl:template>
107
108 <xsl:template mode="mal2html.inline.mode" match="mml:math">
109 <span>
110 <xsl:call-template name="html.class.attr">
111 <xsl:with-param name="class" select="'math'"/>
112 </xsl:call-template>
113 <xsl:call-template name="html.lang.attrs"/>
114 <xsl:element name="math" namespace="{$html.mathml.namespace}">
115 <xsl:for-each select="@*[name(.) != 'display']
116 [not(starts-with(namespace-uri(.), 'http://projectmallard.org/'))]">
117 <xsl:copy-of select="."/>
118 </xsl:for-each>
119 <xsl:attribute name="display">
120 <xsl:value-of select="'inline'"/>
121 </xsl:attribute>
122 <xsl:apply-templates mode="mal2html.math.mode"/>
123 </xsl:element>
124 </span>
125 </xsl:template>
126
127 </xsl:stylesheet>