summaryrefslogtreecommitdiff
path: root/xslt/mallard/html/mal2html-media.xsl
blob: 20308b51d4692691687b9daf78224b812d757e2a (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
<?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, write to the
Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
02111-1307, USA.
-->

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                xmlns:mal="http://www.gnome.org/~shaunm/mallard"
                xmlns="http://www.w3.org/1999/xhtml"
                version="1.0">

<!--!!==========================================================================
Mallard to HTML - Media Elements

REMARK: Describe this module
-->


<!-- == Matched Templates == -->

<!-- = mal2html.block.mode % media = -->
<xsl:template mode="mal2html.block.mode" match="mal:media">
  <xsl:param name="first_child" select="not(preceding-sibling::*)"/>
  <xsl:choose>
    <xsl:when test="@type = 'image'">
      <div>
        <xsl:attribute name="class">
          <xsl:text>media media-image</xsl:text>
          <xsl:if test="$first_child">
            <xsl:text> first-child</xsl:text>
          </xsl:if>
        </xsl:attribute>
        <img src="{@src}">
          <xsl:copy-of select="@height"/>
          <xsl:copy-of select="@width"/>
          <xsl:attribute name="alt">
            <!-- FIXME: This is not ideal.  Nested block container elements
                 will introduce lots of garbage whitespace.  But then, XML
                 processors are supposed to normalize whitespace in attribute
                 values anyway.  Ideally, we'd have a set of modes for text
                 conversion.  That'd probably be best handled in a set of
                 mal2text stylesheets.
            -->
            <xsl:for-each select="mal:*">
              <xsl:if test="position() &gt; 1">
                <xsl:text>&#x000A;</xsl:text>
              </xsl:if>
              <xsl:value-of select="string(.)"/>
            </xsl:for-each>
          </xsl:attribute>
        </img>
      </div>
    </xsl:when>
    <xsl:otherwise>
      <xsl:for-each select="mal:*">
        <xsl:apply-templates mode="db2html.block.mode" select=".">
          <xsl:with-param name="first_child" select="position() = 1 and $first_child"/>
        </xsl:apply-templates>
      </xsl:for-each>
    </xsl:otherwise>
  </xsl:choose>
</xsl:template>

<!-- = mal2html.inline.mode % media = -->
<xsl:template mode="mal2html.inline.mode" match="mal:media">
  <xsl:choose>
    <xsl:when test="@type = 'image'">
      <span class="media media-image">
        <img src="{@src}">
          <xsl:copy-of select="@height"/>
          <xsl:copy-of select="@width"/>
          <xsl:attribute name="alt">
            <xsl:value-of select="."/>
          </xsl:attribute>
        </img>
      </span>
    </xsl:when>
    <xsl:otherwise>
      <xsl:apply-templates mode="db2html.inline.mode"/>
    </xsl:otherwise>
  </xsl:choose>
</xsl:template>

</xsl:stylesheet>