annotate bug-list.xsl @ 3:36ae3ec94442

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