0
|
1 <?xml version="1.0" encoding="UTF-8"?>
|
|
2 <xsl:stylesheet version="1.0"
|
4
|
3 xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:exsl="http://exslt.org/common"
|
|
4 extension-element-prefixes="exsl">
|
|
5 <xsl:output method="text" indent="yes" />
|
|
6
|
5
|
7 <!-- PARAMETERS -->
|
|
8
|
|
9 <!-- chargeset - название аккаунта, на который вести расходы -->
|
|
10 <xsl:param name="chargeset" />
|
|
11
|
|
12 <!-- root_task_id - id корневой задачи, в которую будут организованы все
|
|
13 задачи -->
|
|
14 <xsl:param name="root_task_id" />
|
|
15
|
|
16 <!-- root_task - описание корневой задачи -->
|
|
17 <xsl:param name="root_task" />
|
|
18
|
|
19 <!-- GLOBAL VARIABLES -->
|
4
|
20 <xsl:variable name="resources"
|
|
21 select="document('resources.xml')/resources/resource" />
|
|
22
|
3
|
23 <xsl:variable name="bugs" select="/bugzilla/bug" />
|
4
|
24
|
3
|
25 <xsl:key name="bugid" match="/bugzilla/bug" use="string(bug_id)" />
|
4
|
26
|
|
27 <xsl:variable name="roots" select="$bugs[not(blocked[key('bugid',.)])]" />
|
1
|
28
|
|
29 <!-- BUILD BUG TREE -->
|
|
30 <xsl:variable name="tree">
|
|
31 <xsl:apply-templates mode="tree" select="$roots" />
|
|
32 </xsl:variable>
|
|
33
|
|
34 <xsl:template match="bug" mode="tree">
|
|
35 <xsl:element name="bug">
|
|
36 <xsl:attribute name="id"><xsl:value-of select="bug_id" /></xsl:attribute>
|
3
|
37 <xsl:if test="component = 'product' or not(number(estimated_time))">
|
5
|
38 <xsl:attribute name="group"><xsl:value-of select="boolean(1)" /></xsl:attribute>
|
1
|
39 </xsl:if>
|
|
40 <xsl:for-each select="dependson">
|
|
41 <xsl:apply-templates mode="tree" select="key('bugid', .)" />
|
|
42 </xsl:for-each>
|
|
43 </xsl:element>
|
|
44 </xsl:template>
|
|
45
|
|
46 <!-- CALCULATE RELATIONS -->
|
|
47 <xsl:variable name="relations">
|
3
|
48 <xsl:apply-templates select="$bugs" mode="relations" />
|
1
|
49 </xsl:variable>
|
|
50
|
|
51 <xsl:template match="bug" mode="relations">
|
|
52 <xsl:variable name="bugid" select="string(bug_id)" />
|
|
53 <bug id="{$bugid}">
|
|
54 <xsl:apply-templates select="exsl:node-set($tree)//bug[@id = $bugid]"
|
|
55 mode="traverse-relations">
|
|
56 </xsl:apply-templates>
|
|
57 </bug>
|
|
58 </xsl:template>
|
|
59
|
|
60 <xsl:template match="bug" mode="traverse-relations">
|
|
61 <xsl:variable name="bugid" select="@id" />
|
3
|
62 <xsl:variable name="path" select="ancestor::bug" />
|
|
63 <xsl:variable name="level" select="count($path)" />
|
5
|
64 <xsl:for-each select="$path[@group]">
|
3
|
65 <xsl:variable name="pos" select="position()" />
|
4
|
66 <xsl:variable name="rank" select="$level - $pos" />
|
3
|
67 <rel container="{@id}" rank="{$rank}" level="{$level}">
|
5
|
68 <xsl:for-each select="$path[position() >= $pos and @group]">
|
3
|
69 <bug id="{@id}" />
|
|
70 </xsl:for-each>
|
|
71 </rel>
|
1
|
72 </xsl:for-each>
|
|
73 </xsl:template>
|
|
74
|
|
75 <!-- CALCULATE STRUCTURE -->
|
|
76
|
3
|
77 <xsl:variable name="parents">
|
1
|
78 <xsl:apply-templates select="exsl:node-set($relations)"
|
3
|
79 mode="parents" />
|
|
80 </xsl:variable>
|
|
81
|
|
82 <xsl:template match="bug" mode="parents">
|
|
83 <xsl:variable name="parent"
|
|
84 select="rel[ not(../rel/@rank < @rank) ][1]" />
|
|
85 <bug id="{@id}" parent="{$parent/@container}" rank="{$parent/@rank}"
|
|
86 level="{$parent/@level}" />
|
|
87 </xsl:template>
|
|
88
|
|
89 <xsl:variable name="structure">
|
5
|
90 <xsl:choose>
|
|
91 <xsl:when test="$root_task">
|
|
92 <bug id="_root" desc="{$root_task}" group="true">
|
|
93 <xsl:apply-templates select="$roots" mode="structure"/>
|
|
94 </bug>
|
|
95 </xsl:when>
|
|
96 <xsl:otherwise>
|
|
97 <xsl:apply-templates select="$roots" mode="structure"/>
|
|
98 </xsl:otherwise>
|
|
99 </xsl:choose>
|
1
|
100 </xsl:variable>
|
|
101
|
|
102 <xsl:template match="bug" mode="structure">
|
3
|
103 <xsl:variable name="id" select="string(bug_id)" />
|
|
104 <xsl:variable name="self" select="." />
|
5
|
105 <xsl:variable name="children"
|
|
106 select="exsl:node-set($parents)/bug[@parent = $id]" />
|
|
107 <xsl:element name="bug">
|
|
108 <xsl:attribute name="id"><xsl:value-of select="$id" /></xsl:attribute>
|
|
109 <xsl:attribute name="desc"><xsl:value-of select="short_desc" /></xsl:attribute>
|
|
110
|
|
111 <xsl:if test="$children">
|
|
112 <xsl:attribute name="group"><xsl:value-of select="boolean($children)" /></xsl:attribute>
|
|
113
|
|
114 <xsl:for-each select="$children">
|
|
115 <xsl:variable name="child" select="@id" />
|
|
116 <xsl:apply-templates select="$bugs[bug_id = $child]"
|
|
117 mode="structure" />
|
|
118 </xsl:for-each>
|
|
119
|
|
120 </xsl:if>
|
|
121
|
|
122 <!-- filter out dependencies -->
|
3
|
123 <xsl:variable name="dependencies"
|
|
124 select="dependson[not(text() = exsl:node-set($parents)/bug[@parent = $id]/@id)]" />
|
5
|
125 <xsl:for-each select="$dependencies">
|
|
126 <dependency id="{.}" />
|
|
127 </xsl:for-each>
|
|
128 </xsl:element>
|
1
|
129 </xsl:template>
|
|
130
|
4
|
131 <!-- output -->
|
0
|
132 <xsl:template match="/">
|
4
|
133 <xsl:apply-templates select="exsl:node-set($structure)/bug">
|
|
134 <xsl:with-param name="indent" select="0" />
|
5
|
135 <xsl:with-param name="chargeset" select="$chargeset"/>
|
4
|
136 </xsl:apply-templates>
|
0
|
137 </xsl:template>
|
|
138
|
|
139 <xsl:template match="bug">
|
|
140 <xsl:param name="indent" select="0" />
|
5
|
141 <xsl:param name="chargeset" />
|
4
|
142 <xsl:variable name="id" select="@id" />
|
|
143 <xsl:variable name="details" select="$bugs[bug_id = $id]" />
|
5
|
144
|
|
145 <!-- task header -->
|
0
|
146 <xsl:call-template name="start-task">
|
|
147 <xsl:with-param name="indent" select="$indent" />
|
5
|
148 <xsl:with-param name="id">
|
|
149 <xsl:call-template name="bug-local-name">
|
|
150 <xsl:with-param name="id" select="@id" />
|
|
151 </xsl:call-template>
|
|
152 </xsl:with-param>
|
|
153 <xsl:with-param name="desc" select="@desc" />
|
0
|
154 </xsl:call-template>
|
5
|
155
|
|
156 <xsl:if test="$chargeset">
|
|
157 <xsl:call-template name="println">
|
|
158 <xsl:with-param name="indent" select="$indent + 1"/>
|
|
159 <xsl:with-param name="text" select="concat('chargeset ', $chargeset)"/>
|
|
160 </xsl:call-template>
|
|
161 </xsl:if>
|
|
162
|
|
163 <!-- task details -->
|
|
164 <xsl:choose>
|
|
165 <xsl:when test="@group">
|
|
166 <!-- DEBUG -->
|
|
167 <xsl:call-template name="comment">
|
|
168 <xsl:with-param name="indent" select="$indent + 1" />
|
|
169 <xsl:with-param name="comment" select="'group'" />
|
|
170 </xsl:call-template>
|
|
171
|
0
|
172
|
5
|
173 <xsl:apply-templates select="$details/node()"
|
|
174 mode="group-details">
|
4
|
175 <xsl:with-param name="indent" select="$indent + 1" />
|
5
|
176 </xsl:apply-templates>
|
0
|
177
|
5
|
178 <xsl:if
|
|
179 test="number($details/estimated_time) or number($details/actual_time) or number($details/remaining_time)">
|
|
180 <xsl:call-template name="start-task">
|
|
181 <xsl:with-param name="indent" select="$indent + 1" />
|
|
182 <xsl:with-param name="id" select="'manage'" />
|
|
183 <xsl:with-param name="desc" select="@desc" />
|
|
184 </xsl:call-template>
|
|
185 <xsl:apply-templates
|
|
186 select="$details/estimated_time | $details/actual_time | $details/remaining_time | $details/assigned_to"
|
|
187 mode="task-details">
|
|
188 <xsl:with-param name="indent" select="$indent + 2" />
|
|
189 </xsl:apply-templates>
|
|
190 <xsl:call-template name="end-task">
|
|
191 <xsl:with-param name="indent" select="$indent + 1" />
|
|
192 </xsl:call-template>
|
|
193 </xsl:if>
|
|
194 </xsl:when>
|
|
195 <xsl:otherwise>
|
|
196 <xsl:apply-templates select="$details/node()"
|
|
197 mode="task-details">
|
|
198 <xsl:with-param name="indent" select="$indent + 1" />
|
|
199 </xsl:apply-templates>
|
|
200 </xsl:otherwise>
|
|
201 </xsl:choose>
|
|
202
|
|
203 <!-- subtasks and dependencies -->
|
4
|
204 <xsl:apply-templates>
|
|
205 <xsl:with-param name="indent" select="$indent + 1" />
|
5
|
206 <xsl:with-param name="referer" select="." />
|
4
|
207 </xsl:apply-templates>
|
0
|
208
|
|
209 <xsl:call-template name="end-task">
|
|
210 <xsl:with-param name="indent" select="$indent" />
|
|
211 </xsl:call-template>
|
|
212 </xsl:template>
|
|
213
|
5
|
214 <xsl:template match="dependency">
|
|
215 <xsl:param name="indent" />
|
|
216 <xsl:param name="referer" />
|
|
217 <xsl:call-template name="println">
|
|
218 <xsl:with-param name="indent" select="$indent" />
|
|
219 <xsl:with-param name="text">
|
|
220 <xsl:text>depends </xsl:text>
|
|
221 <xsl:call-template name="bug-reference">
|
|
222 <xsl:with-param name="id" select="@id" />
|
|
223 <xsl:with-param name="referer" select="$referer" />
|
|
224 </xsl:call-template>
|
|
225 </xsl:with-param>
|
|
226 </xsl:call-template>
|
|
227 </xsl:template>
|
|
228
|
|
229
|
|
230 <xsl:template match="text()" />
|
|
231
|
|
232 <!-- TASK ATTRIBUTES -->
|
|
233
|
4
|
234 <xsl:template match="estimated_time" mode="task-details">
|
5
|
235 <xsl:param name="indent" />
|
4
|
236 <xsl:if test="number(.)">
|
5
|
237 <xsl:call-template name="println">
|
|
238 <xsl:with-param name="indent" select="$indent" />
|
|
239 <xsl:with-param name="text" select="concat('effort ', .,'h')" />
|
|
240 </xsl:call-template>
|
4
|
241 </xsl:if>
|
|
242 </xsl:template>
|
|
243
|
|
244 <xsl:template match="assigned_to" mode="task-details">
|
5
|
245 <xsl:param name="indent" />
|
4
|
246 <xsl:variable name="email" select="string(.)" />
|
|
247 <xsl:variable name="resource" select="$resources[@email = $email]/@id" />
|
|
248 <xsl:if test="$resource">
|
5
|
249 <xsl:call-template name="println">
|
|
250 <xsl:with-param name="indent" select="$indent" />
|
|
251 <xsl:with-param name="text" select="concat('allocate ', $resource)" />
|
|
252 </xsl:call-template>
|
4
|
253 </xsl:if>
|
|
254 </xsl:template>
|
|
255 <xsl:template match="text()" mode="task-details">
|
|
256 </xsl:template>
|
|
257
|
5
|
258 <xsl:template match="assigned_to" mode="group-details">
|
|
259 <xsl:param name="indent" />
|
|
260 <xsl:variable name="email" select="string(.)" />
|
|
261 <xsl:variable name="resource" select="$resources[@email = $email]/@id" />
|
|
262 <xsl:if test="$resource">
|
|
263 <xsl:call-template name="println">
|
|
264 <xsl:with-param name="indent" select="$indent" />
|
|
265 <xsl:with-param name="text"
|
|
266 select="concat('responsible ', $resource)" />
|
|
267 </xsl:call-template>
|
|
268 </xsl:if>
|
|
269 </xsl:template>
|
|
270 <xsl:template match="text()" mode="group-details">
|
4
|
271 </xsl:template>
|
|
272
|
5
|
273 <!-- PRIMITIVES -->
|
4
|
274
|
|
275
|
|
276
|
|
277 <xsl:template name="bug-local-name">
|
|
278 <xsl:param name="id" />
|
|
279 <xsl:value-of select="concat('bug',$id)" />
|
|
280 </xsl:template>
|
|
281
|
|
282
|
|
283 <xsl:template name="bug-reference">
|
|
284 <xsl:param name="id" />
|
|
285 <xsl:param name="referer" />
|
|
286
|
|
287 <xsl:variable name="refererPathFragment">
|
|
288 <bug id="#root" />
|
|
289 <xsl:for-each select="$referer/ancestor-or-self::bug">
|
|
290 <bug id="{@id}" />
|
|
291 </xsl:for-each>
|
|
292 </xsl:variable>
|
|
293 <xsl:variable name="targetPathFragment">
|
|
294 <bug id="#root" />
|
|
295 <xsl:for-each
|
5
|
296 select="exsl:node-set($structure)//bug[@id = $id]/ancestor-or-self::bug">
|
4
|
297 <bug id="{@id}" />
|
|
298 </xsl:for-each>
|
|
299 </xsl:variable>
|
|
300 <xsl:variable name="path"
|
|
301 select="exsl:node-set($refererPathFragment)/bug" />
|
|
302 <xsl:variable name="targetPath"
|
|
303 select="exsl:node-set($targetPathFragment)/bug" />
|
|
304
|
|
305 <!-- find closest shared container id -->
|
|
306 <xsl:variable name="join"
|
|
307 select="($path[@id = $targetPath/@id])[position() = last() ]/@id" />
|
|
308
|
|
309 <!-- how many levels we need to up -->
|
|
310 <xsl:variable name="depth"
|
|
311 select="count($path[@id = $join]/following-sibling::node())" />
|
|
312
|
|
313 <!-- DEBUG -->
|
|
314 <!-- <xsl:value-of select="concat('id=', $id, ',referer=', $referer/@id)"
|
|
315 /> <xsl:text>, path=</xsl:text> <xsl:for-each select="$targetPath"> <xsl:value-of
|
|
316 select="concat(name(),@id)" /> <xsl:if test="position() != last()"> <xsl:text>-</xsl:text>
|
|
317 </xsl:if> </xsl:for-each> -->
|
|
318 <!-- DEBUG -->
|
|
319 <!-- <xsl:value-of select="concat(', join=', $join,', depth=', $depth,'
|
|
320 ')" /> -->
|
|
321
|
|
322 <!-- PRINT REFERENCE -->
|
|
323 <xsl:call-template name="repeat">
|
|
324 <xsl:with-param name="value" select="'!'" />
|
|
325 <xsl:with-param name="count" select="$depth" />
|
|
326 </xsl:call-template>
|
|
327 <xsl:for-each select="$targetPath[@id = $join]/following-sibling::node()">
|
|
328 <xsl:call-template name="bug-local-name">
|
|
329 <xsl:with-param name="id" select="@id" />
|
|
330 </xsl:call-template>
|
|
331 <xsl:if test="position() != last()">
|
|
332 <xsl:text>.</xsl:text>
|
|
333 </xsl:if>
|
|
334 </xsl:for-each>
|
|
335
|
0
|
336 </xsl:template>
|
|
337
|
|
338 <xsl:template name="start-task">
|
|
339 <xsl:param name="indent" />
|
4
|
340 <xsl:param name="id" />
|
|
341 <xsl:param name="desc" />
|
0
|
342 <xsl:call-template name="begin-line">
|
|
343 <xsl:with-param name="indent" select="$indent" />
|
|
344 </xsl:call-template>
|
|
345 <xsl:text>task </xsl:text>
|
5
|
346 <xsl:value-of select="$id" />
|
4
|
347 <xsl:value-of select="concat(' "',$desc,'" {')" />
|
0
|
348 <xsl:call-template name="end-line" />
|
|
349 </xsl:template>
|
|
350
|
|
351 <xsl:template name="end-task">
|
|
352 <xsl:param name="indent" />
|
|
353 <xsl:call-template name="begin-line">
|
|
354 <xsl:with-param name="indent" select="$indent" />
|
|
355 </xsl:call-template>
|
|
356 <xsl:text>}</xsl:text>
|
|
357 <xsl:call-template name="end-line" />
|
|
358 </xsl:template>
|
|
359
|
|
360 <xsl:template name="begin-line">
|
|
361 <xsl:param name="indent" />
|
|
362 <xsl:if test="number($indent) > 0">
|
|
363 <xsl:text> </xsl:text>
|
|
364 <xsl:call-template name="begin-line">
|
|
365 <xsl:with-param name="indent" select="$indent - 1" />
|
|
366 </xsl:call-template>
|
|
367 </xsl:if>
|
|
368 </xsl:template>
|
5
|
369
|
0
|
370 <xsl:template name="end-line">
|
|
371 <xsl:text>
</xsl:text>
|
|
372 </xsl:template>
|
4
|
373
|
|
374 <xsl:template name="repeat">
|
|
375 <xsl:param name="value" />
|
|
376 <xsl:param name="count" select="0" />
|
|
377
|
|
378 <xsl:if test="number($count)">
|
|
379 <xsl:copy-of select="$value" />
|
|
380 <xsl:call-template name="repeat">
|
|
381 <xsl:with-param name="value" select="$value" />
|
|
382 <xsl:with-param name="count" select="$count - 1" />
|
|
383 </xsl:call-template>
|
|
384 </xsl:if>
|
|
385 </xsl:template>
|
5
|
386
|
|
387 <xsl:template name="comment">
|
|
388 <xsl:param name="indent" />
|
|
389 <xsl:param name="comment" />
|
|
390 <xsl:call-template name="println">
|
|
391 <xsl:with-param name="indent" select="$indent" />
|
|
392 <xsl:with-param name="text">
|
|
393 <xsl:text># </xsl:text>
|
|
394 <xsl:value-of select="$comment" />
|
|
395 </xsl:with-param>
|
|
396 </xsl:call-template>
|
|
397 </xsl:template>
|
|
398
|
|
399 <xsl:template name="println">
|
|
400 <xsl:param name="indent" />
|
|
401 <xsl:param name="text" />
|
|
402 <xsl:call-template name="begin-line">
|
|
403 <xsl:with-param name="indent" select="$indent" />
|
|
404 </xsl:call-template>
|
|
405 <xsl:value-of select="$text" />
|
|
406 <xsl:call-template name="end-line" />
|
|
407 </xsl:template>
|
0
|
408 </xsl:stylesheet> |