0
|
1 <?xml version="1.0" encoding="UTF-8"?>
|
|
2 <xsl:stylesheet version="1.0"
|
1
|
3 xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:exsl="http://exslt.org/common">
|
|
4 <xsl:output method="xml" indent="yes" />
|
3
|
5 <xsl:variable name="bugs" select="/bugzilla/bug" />
|
|
6 <xsl:key name="bugid" match="/bugzilla/bug" use="string(bug_id)" />
|
1
|
7 <xsl:variable name="roots"
|
3
|
8 select="$bugs[not(blocked[key('bugid',.)])]" />
|
1
|
9
|
|
10 <!-- BUILD BUG TREE -->
|
|
11 <xsl:variable name="tree">
|
|
12 <xsl:apply-templates mode="tree" select="$roots" />
|
|
13 </xsl:variable>
|
|
14
|
|
15 <xsl:template match="bug" mode="tree">
|
|
16 <xsl:element name="bug">
|
|
17 <xsl:attribute name="id"><xsl:value-of select="bug_id" /></xsl:attribute>
|
3
|
18 <xsl:if test="component = 'product' or not(number(estimated_time))">
|
1
|
19 <xsl:attribute name="product"><xsl:value-of select="boolean(1)" /></xsl:attribute>
|
|
20 </xsl:if>
|
|
21 <xsl:for-each select="dependson">
|
|
22 <xsl:apply-templates mode="tree" select="key('bugid', .)" />
|
|
23 </xsl:for-each>
|
|
24 </xsl:element>
|
|
25 </xsl:template>
|
|
26
|
|
27 <!-- CALCULATE RELATIONS -->
|
|
28 <xsl:variable name="relations">
|
3
|
29 <xsl:apply-templates select="$bugs" mode="relations" />
|
1
|
30 </xsl:variable>
|
|
31
|
|
32 <xsl:template match="bug" mode="relations">
|
|
33 <xsl:variable name="bugid" select="string(bug_id)" />
|
|
34 <bug id="{$bugid}">
|
|
35 <xsl:apply-templates select="exsl:node-set($tree)//bug[@id = $bugid]"
|
|
36 mode="traverse-relations">
|
|
37 </xsl:apply-templates>
|
|
38 </bug>
|
|
39 </xsl:template>
|
|
40
|
|
41 <xsl:template match="bug" mode="traverse-relations">
|
|
42 <xsl:variable name="bugid" select="@id" />
|
3
|
43 <xsl:variable name="path" select="ancestor::bug" />
|
|
44 <xsl:variable name="level" select="count($path)" />
|
|
45 <xsl:for-each select="$path[@product]">
|
|
46 <xsl:variable name="pos" select="position()" />
|
1
|
47 <xsl:variable name="rank" select="$level - position()" />
|
3
|
48 <rel container="{@id}" rank="{$rank}" level="{$level}">
|
|
49 <xsl:for-each select="$path[position() >= $pos]">
|
|
50 <bug id="{@id}" />
|
|
51 </xsl:for-each>
|
|
52 </rel>
|
1
|
53 </xsl:for-each>
|
|
54 </xsl:template>
|
|
55
|
|
56 <!-- CALCULATE STRUCTURE -->
|
|
57
|
3
|
58 <xsl:variable name="parents">
|
1
|
59 <xsl:apply-templates select="exsl:node-set($relations)"
|
3
|
60 mode="parents" />
|
|
61 </xsl:variable>
|
|
62
|
|
63 <xsl:template match="bug" mode="parents">
|
|
64 <xsl:variable name="parent"
|
|
65 select="rel[ not(../rel/@rank < @rank) ][1]" />
|
|
66 <bug id="{@id}" parent="{$parent/@container}" rank="{$parent/@rank}"
|
|
67 level="{$parent/@level}" />
|
|
68 </xsl:template>
|
|
69
|
|
70 <xsl:variable name="structure">
|
|
71 <xsl:apply-templates select="$roots" mode="structure" />
|
1
|
72 </xsl:variable>
|
|
73
|
|
74 <xsl:template match="bug" mode="structure">
|
3
|
75 <xsl:variable name="id" select="string(bug_id)" />
|
|
76 <xsl:variable name="self" select="." />
|
|
77 <bug id="{$id}">
|
|
78 <xsl:for-each select="exsl:node-set($parents)/bug[@parent = $id]">
|
|
79 <xsl:variable name="child" select="@id" />
|
|
80 <xsl:apply-templates select="$bugs[bug_id = $child]"
|
|
81 mode="structure" />
|
|
82 </xsl:for-each>
|
|
83 <xsl:variable name="dependencies"
|
|
84 select="dependson[not(text() = exsl:node-set($parents)/bug[@parent = $id]/@id)]" />
|
|
85 <xsl:if test="$dependencies">
|
|
86 <depends>
|
|
87 <xsl:for-each select="$dependencies">
|
|
88 <bug id="{.}" />
|
|
89 </xsl:for-each>
|
|
90 </depends>
|
|
91 </xsl:if>
|
|
92 </bug>
|
1
|
93 </xsl:template>
|
|
94
|
|
95 <!-- -->
|
0
|
96 <xsl:template match="/">
|
1
|
97 <root>
|
|
98 <xsl:copy-of select="$tree" />
|
|
99 <xsl:copy-of select="$relations" />
|
3
|
100 <xsl:copy-of select="$parents" />
|
1
|
101 <xsl:copy-of select="$structure" />
|
|
102 </root>
|
0
|
103 </xsl:template>
|
|
104
|
|
105 <xsl:template match="bug">
|
1
|
106 <xsl:value-of select="bug_id" />
|
|
107 <xsl:text>
</xsl:text>
|
|
108 </xsl:template>
|
|
109
|
|
110 <xsl:template match="bug[component = 'product']">
|
|
111 <xsl:value-of select="bug_id" />
|
|
112 <xsl:text>:
</xsl:text>
|
|
113 <xsl:for-each select="dependson">
|
|
114 <xsl:apply-templates select="key('bugid', .)" />
|
|
115 </xsl:for-each>
|
|
116 <xsl:text>---END---
</xsl:text>
|
0
|
117 </xsl:template>
|
|
118
|
|
119 <xsl:template match="text()" />
|
|
120
|
|
121 <xsl:template name="bug-template">
|
|
122 <xsl:param name="indent" select="0" />
|
|
123 <xsl:variable name="isOrganizing" select="component = 'product'"></xsl:variable>
|
|
124
|
|
125 <xsl:call-template name="start-task">
|
|
126 <xsl:with-param name="indent" select="$indent" />
|
|
127 </xsl:call-template>
|
|
128
|
|
129 <xsl:if test="$isOrganizing">
|
|
130
|
|
131 </xsl:if>
|
|
132
|
|
133 <xsl:choose>
|
|
134 <xsl:when test="$isOrganizing">
|
|
135 <xsl:for-each select="dependson">
|
|
136 <xsl:for-each select="key('bugs-key', .)">
|
|
137 <xsl:call-template name="bug-template">
|
|
138 <xsl:with-param name="indent" select="$indent + 1" />
|
|
139 </xsl:call-template>
|
|
140 </xsl:for-each>
|
|
141 </xsl:for-each>
|
|
142 </xsl:when>
|
|
143 <xsl:otherwise>
|
|
144 <xsl:if test="number(estimated_time)">
|
|
145 <xsl:call-template name="begin-line">
|
|
146 <xsl:with-param name="indent" select="$indent + 1" />
|
|
147 </xsl:call-template>
|
|
148 <xsl:value-of select="concat('effort ', estimated_time, 'h')" />
|
|
149 <xsl:call-template name="end-line" />
|
|
150 </xsl:if>
|
|
151 </xsl:otherwise>
|
|
152 </xsl:choose>
|
|
153
|
|
154 <xsl:call-template name="end-task">
|
|
155 <xsl:with-param name="indent" select="$indent" />
|
|
156 </xsl:call-template>
|
|
157 </xsl:template>
|
|
158
|
|
159 <xsl:template name="make-bug-id">
|
|
160 <xsl:param name="id"></xsl:param>
|
|
161 <xsl:value-of select="concat('bug', $id)"></xsl:value-of>
|
|
162 </xsl:template>
|
|
163
|
|
164 <xsl:template name="start-task">
|
|
165 <xsl:param name="indent" />
|
|
166 <xsl:call-template name="begin-line">
|
|
167 <xsl:with-param name="indent" select="$indent" />
|
|
168 </xsl:call-template>
|
|
169 <xsl:text>task </xsl:text>
|
|
170 <xsl:call-template name="make-bug-id">
|
|
171 <xsl:with-param name="id" select="bug_id" />
|
|
172 </xsl:call-template>
|
|
173 <xsl:value-of select="concat(' "',short_desc,'" {')" />
|
|
174 <xsl:call-template name="end-line" />
|
|
175 </xsl:template>
|
|
176
|
|
177 <xsl:template name="end-task">
|
|
178 <xsl:param name="indent" />
|
|
179 <xsl:call-template name="begin-line">
|
|
180 <xsl:with-param name="indent" select="$indent" />
|
|
181 </xsl:call-template>
|
|
182 <xsl:text>}</xsl:text>
|
|
183 <xsl:call-template name="end-line" />
|
|
184 </xsl:template>
|
|
185
|
|
186 <xsl:template name="begin-line">
|
|
187 <xsl:param name="indent" />
|
|
188 <xsl:if test="number($indent) > 0">
|
|
189 <xsl:text> </xsl:text>
|
|
190 <xsl:call-template name="begin-line">
|
|
191 <xsl:with-param name="indent" select="$indent - 1" />
|
|
192 </xsl:call-template>
|
|
193 </xsl:if>
|
|
194 </xsl:template>
|
|
195 <xsl:template name="end-line">
|
|
196 <xsl:text>
</xsl:text>
|
|
197 </xsl:template>
|
|
198 </xsl:stylesheet> |