summaryrefslogtreecommitdiff
path: root/xslt/mallard/cache/mal-cache.xsl
blob: 6305e0b9b869031ada45d5c31bcbe2987f46c4ad (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
140
141
<?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:site='http://projectmallard.org/site/1.0/'
                xmlns='http://projectmallard.org/1.0/'
                version='1.0'>

<!--!!==========================================================================
Mallard Cache Files
Generate Mallard cache files from cache input files.

FIXME
-->

<xsl:output omit-xml-declaration="yes"/>

<xsl:include href="../common/mal-link.xsl"/>


<!--**==========================================================================
mal.cache.id
-->
<xsl:template name="mal.cache.id">
  <xsl:param name="node" select="."/>
  <xsl:param name="node_in"/>
  <xsl:attribute name="id">
    <xsl:call-template name="mal.link.linkid">
      <xsl:with-param name="node" select="$node"/>
    </xsl:call-template>
  </xsl:attribute>
</xsl:template>


<!--**==========================================================================
mal.cache.info
-->
<xsl:template name="mal.cache.info">
  <xsl:param name="node" select="."/>
  <xsl:param name="info" select="$node/mal:info"/>
  <xsl:param name="node_in"/>
  <info>
    <xsl:for-each select="$info/*">
      <xsl:choose>
        <xsl:when test="$node/parent::mal:stack[@type = 'series'] and
                        self::mal:link[@type = 'next']"/>
        <xsl:otherwise>
          <xsl:copy-of select="."/>
        </xsl:otherwise>
      </xsl:choose>
    </xsl:for-each>
    <xsl:if test="$node/parent::mal:stack[@type = 'series']">
      <xsl:variable name="next" select="$node/following-sibling::mal:page[1]"/>
      <xsl:if test="$next">
        <link type="next" xref="{$next/@id}"/>
      </xsl:if>
    </xsl:if>
  </info>
</xsl:template>


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

<!-- = /cache:cache = -->
<xsl:template match='/cache:cache'>
  <cache:cache>
    <xsl:for-each select="mal:page | mal:stack">
      <xsl:apply-templates select="document(@cache:href)/*">
        <xsl:with-param name="node_in" select="."/>
      </xsl:apply-templates>
    </xsl:for-each>
  </cache:cache>
</xsl:template>

<!-- = mal:stack = -->
<xsl:template match="mal:stack">
  <xsl:param name="node_in"/>
  <xsl:apply-templates select="mal:page">
    <xsl:with-param name="node_in" select="$node_in"/>
  </xsl:apply-templates>
</xsl:template>

<!-- = mal:page = -->
<xsl:template match="mal:page">
  <xsl:param name="node_in"/>
  <page>
    <xsl:copy-of select="@*"/>
    <xsl:copy-of select="$node_in/@cache:*"/>
    <xsl:copy-of select="$node_in/@site:*"/>
    <xsl:call-template name="mal.cache.id">
      <xsl:with-param name="node_in" select="$node_in"/>
    </xsl:call-template>
    <xsl:call-template name="mal.cache.info">
      <xsl:with-param name="node_in" select="$node_in"/>
    </xsl:call-template>
    <xsl:apply-templates>
      <xsl:with-param name="node_in" select="$node_in"/>
    </xsl:apply-templates>
  </page>
</xsl:template>

<!-- = mal:section = -->
<xsl:template match="mal:section">
  <xsl:param name="node_in"/>
  <section>
    <xsl:copy-of select="@*"/>
    <xsl:call-template name="mal.cache.id">
      <xsl:with-param name="node_in" select="$node_in"/>
    </xsl:call-template>
    <xsl:call-template name="mal.cache.info">
      <xsl:with-param name="node_in" select="$node_in"/>
    </xsl:call-template>
    <xsl:apply-templates>
      <xsl:with-param name="node_in" select="$node_in"/>
    </xsl:apply-templates>
  </section>
</xsl:template>

<!-- = mal:title = -->
<xsl:template match="mal:title">
  <xsl:copy-of select="."/>
</xsl:template>

<xsl:template match="node() | text()"/>

</xsl:stylesheet>