Annotation of kupu/make.xsl, revision 1.1.1.1
1.1 dwinter 1: <?xml version="1.0" encoding="utf-8"?>
2: <!--
3: ##############################################################################
4: #
5: # Copyright (c) 2003-2005 Kupu Contributors. All rights reserved.
6: #
7: # This software is distributed under the terms of the Kupu
8: # License. See LICENSE.txt for license text. For a list of Kupu
9: # Contributors see CREDITS.txt.
10: #
11: ##############################################################################
12:
13: Generate an HTML template from Kupu distribution files
14:
15: This XSLT is fed a Kupu distribution file (generally dist.kupu) which
16: contains:
17:
18: a) slot definitions,
19:
20: b) feature and part definitions,
21:
22: c) wiring that matches parts to slots,
23:
24: d) an order in which implementations are to be cascaded.
25:
26: If the XSLT processor supports XInclude, the above stated items may of
27: course be located in different files and included later.
28:
29: $Id: make.xsl 14502 2005-07-11 14:06:43Z duncan $
30: -->
31: <xsl:stylesheet
32: xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
33: xmlns:kupu="http://kupu.oscom.org/namespaces/dist"
34: version="1.0"
35: >
36:
37: <xsl:output
38: method="xml"
39: indent="yes"
40: encoding="ascii"
41: omit-xml-declaration="yes"
42: />
43:
44: <xsl:strip-space
45: elements="kupu:*"
46: />
47:
48: <xsl:preserve-space
49: elements="kupu:part"
50: />
51:
52: <!-- ### Global parameters ### -->
53:
54: <!-- debug :: enables some debugging messages; by default false -->
55: <xsl:param
56: name="debug"
57: select="false()"
58: />
59:
60:
61: <!-- ### Templates ### -->
62:
63: <!-- document element -->
64: <xsl:template match="/kupu:dist">
65: <xsl:apply-templates />
66: </xsl:template>
67:
68: <!-- Ignore kupu stuff outside expand -->
69: <xsl:template match="//kupu:*" />
70:
71:
72: <!-- ## Expand mode templates ## -->
73:
74: <!-- Anything in kupu:expand runs in expand mode. This is where the
75: whole things starts. -->
76: <xsl:template match="//kupu:expand">
77: <xsl:apply-templates mode="expand" />
78: </xsl:template>
79:
80: <xsl:template match="//kupu:define-slot" mode="expand">
81: <xsl:variable
82: name="slot"
83: select="@name"
84: />
85:
86: <!-- Debug -->
87: <xsl:if test="$debug">
88: <xsl:comment>
89: Slot named '<xsl:value-of select="$slot" />' defined.
90: </xsl:comment>
91: </xsl:if>
92:
93: <!-- We'll try to find a wiring that tells us what should go into
94: our slot -->
95:
96: <xsl:call-template name="fill-slot">
97: <xsl:with-param
98: name="slot"
99: select="$slot"
100: />
101: </xsl:call-template>
102:
103: </xsl:template>
104:
105: <!-- Named template that looks for an appropriate fill-slot element
106: in a wiring. It recursively browses through implementations; that
107: way wirings of different implementations cascade -->
108: <xsl:template name="fill-slot">
109: <xsl:param name="implno" select="1" />
110: <xsl:param name="slot" />
111:
112: <xsl:variable
113: name="impl"
114: select="//kupu:implementation-order/kupu:implementation[$implno]/@name"
115: />
116:
117: <xsl:variable
118: name="fillnode"
119: select="//kupu:wire[@implementation=$impl]/kupu:fill-slot[@name=$slot]"
120: />
121:
122: <xsl:choose>
123: <!-- if we've found a valid implementation, go for it -->
124: <xsl:when test="$fillnode">
125: <!-- Debug -->
126: <xsl:if test="$debug">
127: <xsl:comment>
128: Found wiring for slot '<xsl:value-of select="$slot" />',
129: at implementation no. <xsl:value-of select="$implno" />,
130: '<xsl:value-of select="$impl" />'.
131: </xsl:comment>
132: </xsl:if>
133: <xsl:apply-templates select="$fillnode" mode="expand" />
134: </xsl:when>
135: <xsl:otherwise>
136: <!-- Cascade onto the next implementation under two circumstances:
137: a) A specific implementation wasn't request: not(@implementation)
138: b) We're already in the last implementation -->
139: <xsl:choose>
140: <xsl:when test="$implno <= count(//kupu:implementation-order/kupu:implementation)">
141: <xsl:call-template name="fill-slot">
142: <xsl:with-param name="implno" select="$implno+1" />
143: <xsl:with-param name="slot" select="$slot" />
144: </xsl:call-template>
145: </xsl:when>
146: <xsl:otherwise>
147: <xsl:comment>
148: Cannot find wiring for slot '<xsl:value-of select="$slot" />'.
149: </xsl:comment>
150: </xsl:otherwise>
151: </xsl:choose>
152: </xsl:otherwise>
153: </xsl:choose>
154:
155: </xsl:template>
156:
157: <xsl:template match="//kupu:insert-ids" mode="expand">
158: <xsl:apply-templates select="//kupu:id" mode="expand" />
159: </xsl:template>
160: <xsl:template match="//kupu:id" mode="expand">
161: <xsl:comment><xsl:value-of select="." /></xsl:comment>
162: <xsl:text>
163: </xsl:text>
164:
165: </xsl:template>
166:
167: <!-- Handle part insertion; we delegate the work to the named
168: template below -->
169: <xsl:template match="//kupu:insert-part" mode="expand">
170: <xsl:variable
171: name="feature"
172: select="@feature"
173: />
174: <xsl:variable
175: name="part"
176: select="@part"
177: />
178: <xsl:choose>
179: <xsl:when test="//kupu:disable-feature[@name=$feature]">
180: <xsl:if test="$debug">
181: <xsl:comment>
182: Feature '<xsl:value-of select="$feature" />' was disabled.
183: </xsl:comment>
184: </xsl:if>
185: </xsl:when>
186: <xsl:when test="//kupu:disable-part[@feature=$feature and @part=$part]">
187: <xsl:if test="$debug">
188: <xsl:comment>
189: Part '<xsl:value-of select="$part" />' in feature
190: '<xsl:value-of select="$feature" />' was disabled.
191: </xsl:comment>
192: </xsl:if>
193: </xsl:when>
194: <xsl:otherwise>
195: <xsl:call-template name="insert-part">
196: <xsl:with-param
197: name="feature"
198: select="$feature"
199: />
200: <xsl:with-param
201: name="part"
202: select="$part"
203: />
204: </xsl:call-template>
205: </xsl:otherwise>
206: </xsl:choose>
207: </xsl:template>
208:
209: <!-- This template recursively looks for feature/part
210: implementations and inserts the first it finds -->
211: <xsl:template name="insert-part">
212: <xsl:param name="implno" select="1" />
213: <xsl:param name="feature" />
214: <xsl:param name="part" />
215:
216: <!-- The caller can provide us with a specific implementation
217: name; if not provided, fall back to the implementation given
218: in 'implno'. -->
219: <xsl:param name="implementation" />
220:
221: <xsl:variable name="impl">
222: <xsl:choose>
223: <xsl:when test="$implementation">
224: <xsl:value-of select="$implementation" />
225: </xsl:when>
226: <xsl:otherwise>
227: <xsl:value-of
228: select="//kupu:implementation-order/kupu:implementation[$implno]/@name"
229: />
230: </xsl:otherwise>
231: </xsl:choose>
232: </xsl:variable>
233:
234: <xsl:variable
235: name="partnode"
236: select="//kupu:feature[@name=$feature and @implementation=$impl]/kupu:part[@name=$part]"
237: />
238:
239: <xsl:choose>
240: <!-- if we've found a valid implementation, go for it -->
241: <xsl:when test="$partnode">
242: <!-- Debug -->
243: <xsl:if test="$debug">
244: <xsl:comment>
245: Found feature '<xsl:value-of select="$feature" />',
246: part '<xsl:value-of select="$part" />' at implementation no.
247: <xsl:value-of select="$implno" />, '<xsl:value-of select="$impl" />'.
248: </xsl:comment>
249: </xsl:if>
250: <xsl:apply-templates select="$partnode" mode="expand" />
251: </xsl:when>
252: <xsl:otherwise>
253: <!-- Cascade onto the next implementation under two circumstances:
254: a) A specific implementation wasn't request: not(@implementation)
255: b) We're already in the last implementation -->
256: <xsl:choose>
257: <xsl:when test="not($implementation) and $implno <= count(//kupu:implementation-order/kupu:implementation)">
258: <xsl:call-template name="insert-part">
259: <xsl:with-param name="implno" select="$implno+1" />
260: <xsl:with-param name="feature" select="$feature" />
261: <xsl:with-param name="part" select="$part" />
262: </xsl:call-template>
263: </xsl:when>
264: <xsl:otherwise>
265: <xsl:comment>
266: Cannot find feature '<xsl:value-of select="$feature" />',
267: part '<xsl:value-of select="$part" />'.
268: </xsl:comment>
269: </xsl:otherwise>
270: </xsl:choose>
271: </xsl:otherwise>
272: </xsl:choose>
273: </xsl:template>
274:
275: <!-- Make sure that we stay in expand mode once we are in it -->
276: <xsl:template match="//kupu:*" mode="expand">
277: <xsl:apply-templates mode="expand"/>
278: </xsl:template>
279:
280: <!-- Display other tags (XHTML) verbatim in expand mode -->
281: <xsl:template match="*" mode="expand">
282: <xsl:copy>
283: <xsl:copy-of select="@*" />
284: <xsl:apply-templates mode="expand" />
285: </xsl:copy>
286: </xsl:template>
287:
288: <!-- Copy nodes through verbatim, but omit the id attribute
289: from most of them -->
290: <!-- <xsl:template match="*" mode="expand">
291: <xsl:choose>
292: <xsl:when test="local-name()='xml' or local-name='iframe'">
293: <xsl:copy>
294: <xsl:copy-of select="@*" />
295: <xsl:apply-templates mode="expand" />
296: </xsl:copy>
297: </xsl:when>
298: <xsl:otherwise>
299: <xsl:copy>
300: <xsl:copy-of select="@*[local-name() != 'id']" />
301: <xsl:apply-templates mode="expand" />
302: </xsl:copy>
303: </xsl:otherwise>
304: </xsl:choose>
305: </xsl:template> -->
306:
307: </xsl:stylesheet>
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>