summaryrefslogtreecommitdiff
path: root/xslt/mallard/html/mal2html-gloss.xsl
blob: 749b752480bddb9db75c3abaae52ea459d49e1bb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
<?xml version='1.0' encoding='UTF-8'?><!-- -*- indent-tabs-mode: nil -*- -->
<!--
This program is free software; you can redistribute it and/or modify it under
the terms of the GNU Lesser General Public License as published by the Free
Software Foundation; either version 2 of the License, or (at your option) any
later version.

This program is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
details.

You should have received a copy of the GNU Lesser General Public License
along with this program; see the file COPYING.LGPL.  If not, see <http://www.gnu.org/licenses/>.
-->

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                xmlns:mal="http://projectmallard.org/1.0/"
                xmlns:cache="http://projectmallard.org/cache/1.0/"
                xmlns:gloss="http://projectmallard.org/experimental/gloss/"
                xmlns:exsl="http://exslt.org/common"
                xmlns:str="http://exslt.org/strings"
                xmlns="http://www.w3.org/1999/xhtml"
                exclude-result-prefixes="mal cache gloss exsl str"
                version="1.0">

<!--!!==========================================================================
Mallard to HTML - Glossaries
Support the Mallard Glossary extension.

This stylesheet contains templates and supporting JavaScript to support the
Mallard Glossary extension in HTML.
-->


<!--**==========================================================================
mal2html.gloss.terms
Display the glossary terms for a page or section.

[xsl:params]
$node: The glossary `page` or `section` to output terms for.

This template shows the glossary terms for a page or section. It collects the
terms with the {mal.gloss.terms} template, sorts them, and merges terms with
the same primary title. Terms that are not defined in the same page as $node
include a link to their defining page.
-->
<xsl:template name="mal2html.gloss.terms">
  <xsl:param name="node" select="."/>
  <xsl:variable name="pageid" select="$node/ancestor-or-self::mal:page[1]/@id"/>
  <xsl:variable name="terms_">
    <xsl:call-template name="mal.gloss.terms">
      <xsl:with-param name="node" select="$node"/>
    </xsl:call-template>
  </xsl:variable>
  <xsl:variable name="terms" select="exsl:node-set($terms_)/gloss:term"/>
  <xsl:if test="count($terms) > 0">
    <dl class="list gloss-list">
      <xsl:for-each select="$terms">
        <xsl:sort select="normalize-space(mal:title[1])"/>
        <xsl:for-each select="mal:title">
          <dt class="gloss-term">
            <xsl:apply-templates mode="mal2html.inline.mode" select="node()"/>
          </dt>
        </xsl:for-each>
        <xsl:for-each select="gloss:term">
          <xsl:sort data-type="number" select="number(boolean(*[not(self::mal:title)]))"/>
          <xsl:sort data-type="number" select="number(not(ancestor::mal:page[1]/@id = $pageid))"/>
          <xsl:if test="not(@xref = $pageid)">
            <dd class="gloss-link">
              <a>
                <xsl:attribute name="href">
                  <xsl:call-template name="mal.link.target">
                    <xsl:with-param name="xref" select="@xref"/>
                  </xsl:call-template>
                </xsl:attribute>
                <xsl:attribute name="title">
                  <xsl:call-template name="mal.link.tooltip">
                    <xsl:with-param name="xref" select="@xref"/>
                    <xsl:with-param name="role" select="'gloss:page'"/>
                  </xsl:call-template>
                </xsl:attribute>
                <xsl:call-template name="mal.link.content">
                  <xsl:with-param name="node" select="."/>
                  <xsl:with-param name="xref" select="@xref"/>
                  <xsl:with-param name="role" select="'gloss:page'"/>
                </xsl:call-template>
              </a>
            </dd>
          </xsl:if>
          <xsl:if test="*[not(self::mal:title)]">
            <dd class="gloss-def">
              <xsl:apply-templates mode="mal2html.block.mode"
                                   select="*[not(self::mal:title)]"/>
            </dd>
          </xsl:if>
        </xsl:for-each>
      </xsl:for-each>
    </dl>
  </xsl:if>
</xsl:template>

<xsl:template mode="mal2html.inline.mode" match="gloss:term">
  <xsl:variable name="node" select="."/>
  <a>
    <xsl:call-template name="html.class.attr">
      <xsl:with-param name="class" select="'gloss-term'"/>
    </xsl:call-template>
    <xsl:call-template name="html.lang.attrs"/>
    <xsl:variable name="target">
      <xsl:call-template name="mal.link.target">
        <xsl:with-param name="node" select="$node"/>
      </xsl:call-template>
    </xsl:variable>
    <xsl:choose>
      <xsl:when test="$target = ''">
        <xsl:attribute name="href">
          <xsl:text>#</xsl:text>
        </xsl:attribute>
      </xsl:when>
      <xsl:otherwise>
        <xsl:attribute name="href">
          <xsl:value-of select="$target"/>
        </xsl:attribute>
      </xsl:otherwise>
    </xsl:choose>
    <xsl:apply-templates mode="mal2html.inline.mode"/>
    <xsl:for-each select="$mal.cache">
      <xsl:variable name="terms" select="key('mal.gloss.key', $node/@ref)"/>
      <xsl:for-each select="$terms/mal:info/mal:desc[1]">
        <span class="gloss-desc">
          <xsl:apply-templates mode="mal2html.inline.mode"/>
        </span>
      </xsl:for-each>
    </xsl:for-each>
  </a>
</xsl:template>

</xsl:stylesheet>