summaryrefslogtreecommitdiff
path: root/doc/xslt/xsldoc-check.xsl
blob: 36e50485de8d47d8b5a817cfa714720048ea759b (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
<?xml version='1.0' encoding='UTF-8'?><!-- -*- indent-tabs-mode: nil -*- -->
<!--
xsldoc-check.xsl - Check the data in the xsldoc file
Copyright (C) 2006 Shaun McCance <shaunm@gnome.org>

This program is free software; you can redistribute it and/or modify it
under the terms of the GNU 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 General Public License
for more details.

You should have received a copy of the GNU General Public License along
with this program; if not, see <http://www.gnu.org/licenses/>.
-->
<!--
This program is free software, but that doesn't mean you should use it.
It's a hackish bit of awk and XSLT to do inline XSLT documentation with
a simple syntax in comments.  I had originally tried to make a public
inline documentation system for XSLT using embedded XML, but it just got
very cumbersome.  XSLT should have been designed from the ground up with
an inline documentation format.

None of the existing inline documentation tools (gtk-doc, doxygen, etc.)
really work well for XSLT, so I rolled my own simple comment-based tool.
This tool is sufficient for producing the documentation I need, but I
just don't have the time or inclination to make a robust system suitable
for public use.

You are, of course, free to use any of this.  If you do proliferate this
hack, it is requested (though not required, that would be non-free) that
you atone for your actions.  A good atonement would be contributing to
free software.
-->

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                version="1.0">

<xsl:template match="section">
  <xsl:variable name="section" select="."/>

  <!-- Check if all called templates exist -->
  <xsl:for-each select="metas/meta[name = 'calls-names']/desc">
    <xsl:variable name="name" select="string(.)"/>
    <xsl:choose>
      <xsl:when test="$section/template[name = $name][1]"/>
      <xsl:otherwise>
        <xsl:variable name="template" select="/xsldoc/section/template[name = $name][1]"/>
        <xsl:choose>
          <xsl:when test="$template and
                          $section/metas/meta[name = 'Requires']/desc[. = string($template/../@id)]"/>
          <xsl:otherwise>
            <xsl:message terminate="yes">
              <xsl:text>The stylesheet </xsl:text>
              <xsl:value-of select="$section/@id"/>
              <xsl:text> calls an undefined template </xsl:text>
              <xsl:value-of select="$name"/>
            </xsl:message>
          </xsl:otherwise>
        </xsl:choose>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:for-each>

  <!-- Check if all called modes exist -->
  <xsl:for-each select="metas/meta[name = 'calls-modes']/desc">
    <xsl:variable name="name" select="string(.)"/>
    <xsl:choose>
      <xsl:when test="$section/mode[name = $name][1]"/>
      <xsl:otherwise>
        <xsl:variable name="mode" select="/xsldoc/section/mode[name = $name][1]"/>
        <xsl:choose>
          <xsl:when test="$mode and
                          $section/metas/meta[name = 'Requires']/desc[. = string($mode/../@id)]"/>
          <xsl:otherwise>
            <xsl:message terminate="yes">
              <xsl:text>The stylesheet </xsl:text>
              <xsl:value-of select="$section/@id"/>
              <xsl:text> calls an undefined mode </xsl:text>
              <xsl:value-of select="$name"/>
            </xsl:message>
          </xsl:otherwise>
        </xsl:choose>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:for-each>

  <!-- Check if all used modes exist -->
  <xsl:for-each select="metas/meta[name = 'uses-modes']/desc">
    <xsl:variable name="name" select="string(.)"/>
    <xsl:choose>
      <xsl:when test="$section/mode[name = $name][1]"/>
      <xsl:otherwise>
        <xsl:variable name="mode" select="/xsldoc/section/mode[name = $name][1]"/>
        <xsl:choose>
          <xsl:when test="$mode and
                          $section/metas/meta[name = 'Requires']/desc[. = string($mode/../@id)]"/>
          <xsl:otherwise>
            <xsl:message terminate="yes">
              <xsl:text>The stylesheet </xsl:text>
              <xsl:value-of select="$section/@id"/>
              <xsl:text> implements an undefined mode </xsl:text>
              <xsl:value-of select="$name"/>
            </xsl:message>
          </xsl:otherwise>
        </xsl:choose>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:for-each>

  <!-- Check if all requires are required -->
  <xsl:for-each select="metas/meta[name = 'Requires']/desc">
    <xsl:variable name="name" select="string(.)"/>
    <xsl:variable name="names" select="$section/metas/meta[name = 'calls-names']/desc"/>
    <xsl:variable name="modes" select="$section/metas/meta[name = 'calls-modes']/desc |
                                       $section/metas/meta[name = 'uses-modes']/desc  "/>
    <xsl:variable name="params" select="$section/metas/meta[name = 'uses-params']/desc"/>
    <xsl:choose>
      <xsl:when test="$name = /xsldoc/section[template[string(name) = $names]]/@id"/>
      <xsl:when test="$name = /xsldoc/section[mode[string(name) = $modes]]/@id"/>
      <xsl:when test="$name = /xsldoc/section[param[string(name) = $params]]/@id"/>
      <xsl:otherwise>
        <xsl:message terminate="yes">
          <xsl:text>The stylesheet </xsl:text>
          <xsl:value-of select="$section/@id"/>
          <xsl:text> does not require the stylesheet </xsl:text>
          <xsl:value-of select="$name"/>
        </xsl:message>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:for-each>

</xsl:template>

</xsl:stylesheet>