| 
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 
 | 
| 
 | 
     7 	<xsl:variable name="resources"
 | 
| 
 | 
     8 		select="document('resources.xml')/resources/resource" />
 | 
| 
 | 
     9 
 | 
| 
3
 | 
    10 	<xsl:variable name="bugs" select="/bugzilla/bug" />
 | 
| 
4
 | 
    11 
 | 
| 
3
 | 
    12 	<xsl:key name="bugid" match="/bugzilla/bug" use="string(bug_id)" />
 | 
| 
4
 | 
    13 
 | 
| 
 | 
    14 	<xsl:variable name="roots" select="$bugs[not(blocked[key('bugid',.)])]" />
 | 
| 
1
 | 
    15 
 | 
| 
 | 
    16 	<!-- BUILD BUG TREE -->
 | 
| 
 | 
    17 	<xsl:variable name="tree">
 | 
| 
 | 
    18 		<xsl:apply-templates mode="tree" select="$roots" />
 | 
| 
 | 
    19 	</xsl:variable>
 | 
| 
 | 
    20 
 | 
| 
 | 
    21 	<xsl:template match="bug" mode="tree">
 | 
| 
 | 
    22 		<xsl:element name="bug">
 | 
| 
 | 
    23 			<xsl:attribute name="id"><xsl:value-of select="bug_id" /></xsl:attribute>
 | 
| 
3
 | 
    24 			<xsl:if test="component = 'product' or not(number(estimated_time))">
 | 
| 
1
 | 
    25 				<xsl:attribute name="product"><xsl:value-of select="boolean(1)" /></xsl:attribute>
 | 
| 
 | 
    26 			</xsl:if>
 | 
| 
 | 
    27 			<xsl:for-each select="dependson">
 | 
| 
 | 
    28 				<xsl:apply-templates mode="tree" select="key('bugid', .)" />
 | 
| 
 | 
    29 			</xsl:for-each>
 | 
| 
 | 
    30 		</xsl:element>
 | 
| 
 | 
    31 	</xsl:template>
 | 
| 
 | 
    32 
 | 
| 
 | 
    33 	<!-- CALCULATE RELATIONS -->
 | 
| 
 | 
    34 	<xsl:variable name="relations">
 | 
| 
3
 | 
    35 		<xsl:apply-templates select="$bugs" mode="relations" />
 | 
| 
1
 | 
    36 	</xsl:variable>
 | 
| 
 | 
    37 
 | 
| 
 | 
    38 	<xsl:template match="bug" mode="relations">
 | 
| 
 | 
    39 		<xsl:variable name="bugid" select="string(bug_id)" />
 | 
| 
 | 
    40 		<bug id="{$bugid}">
 | 
| 
 | 
    41 			<xsl:apply-templates select="exsl:node-set($tree)//bug[@id = $bugid]"
 | 
| 
 | 
    42 				mode="traverse-relations">
 | 
| 
 | 
    43 			</xsl:apply-templates>
 | 
| 
 | 
    44 		</bug>
 | 
| 
 | 
    45 	</xsl:template>
 | 
| 
 | 
    46 
 | 
| 
 | 
    47 	<xsl:template match="bug" mode="traverse-relations">
 | 
| 
 | 
    48 		<xsl:variable name="bugid" select="@id" />
 | 
| 
3
 | 
    49 		<xsl:variable name="path" select="ancestor::bug" />
 | 
| 
 | 
    50 		<xsl:variable name="level" select="count($path)" />
 | 
| 
 | 
    51 		<xsl:for-each select="$path[@product]">
 | 
| 
 | 
    52 			<xsl:variable name="pos" select="position()" />
 | 
| 
4
 | 
    53 			<xsl:variable name="rank" select="$level - $pos" />
 | 
| 
3
 | 
    54 			<rel container="{@id}" rank="{$rank}" level="{$level}">
 | 
| 
4
 | 
    55 				<xsl:for-each select="$path[position() >= $pos and @product]">
 | 
| 
3
 | 
    56 					<bug id="{@id}" />
 | 
| 
 | 
    57 				</xsl:for-each>
 | 
| 
 | 
    58 			</rel>
 | 
| 
1
 | 
    59 		</xsl:for-each>
 | 
| 
 | 
    60 	</xsl:template>
 | 
| 
 | 
    61 
 | 
| 
 | 
    62 	<!-- CALCULATE STRUCTURE -->
 | 
| 
 | 
    63 
 | 
| 
3
 | 
    64 	<xsl:variable name="parents">
 | 
| 
1
 | 
    65 		<xsl:apply-templates select="exsl:node-set($relations)"
 | 
| 
3
 | 
    66 			mode="parents" />
 | 
| 
 | 
    67 	</xsl:variable>
 | 
| 
 | 
    68 
 | 
| 
 | 
    69 	<xsl:template match="bug" mode="parents">
 | 
| 
 | 
    70 		<xsl:variable name="parent"
 | 
| 
 | 
    71 			select="rel[ not(../rel/@rank < @rank) ][1]" />
 | 
| 
 | 
    72 		<bug id="{@id}" parent="{$parent/@container}" rank="{$parent/@rank}"
 | 
| 
 | 
    73 			level="{$parent/@level}" />
 | 
| 
 | 
    74 	</xsl:template>
 | 
| 
 | 
    75 
 | 
| 
 | 
    76 	<xsl:variable name="structure">
 | 
| 
 | 
    77 		<xsl:apply-templates select="$roots" mode="structure" />
 | 
| 
1
 | 
    78 	</xsl:variable>
 | 
| 
 | 
    79 
 | 
| 
 | 
    80 	<xsl:template match="bug" mode="structure">
 | 
| 
3
 | 
    81 		<xsl:variable name="id" select="string(bug_id)" />
 | 
| 
 | 
    82 		<xsl:variable name="self" select="." />
 | 
| 
 | 
    83 		<bug id="{$id}">
 | 
| 
 | 
    84 			<xsl:for-each select="exsl:node-set($parents)/bug[@parent = $id]">
 | 
| 
 | 
    85 				<xsl:variable name="child" select="@id" />
 | 
| 
 | 
    86 				<xsl:apply-templates select="$bugs[bug_id = $child]"
 | 
| 
 | 
    87 					mode="structure" />
 | 
| 
 | 
    88 			</xsl:for-each>
 | 
| 
 | 
    89 			<xsl:variable name="dependencies"
 | 
| 
 | 
    90 				select="dependson[not(text() = exsl:node-set($parents)/bug[@parent = $id]/@id)]" />
 | 
| 
 | 
    91 			<xsl:if test="$dependencies">
 | 
| 
 | 
    92 				<depends>
 | 
| 
 | 
    93 					<xsl:for-each select="$dependencies">
 | 
| 
 | 
    94 						<bug id="{.}" />
 | 
| 
 | 
    95 					</xsl:for-each>
 | 
| 
 | 
    96 				</depends>
 | 
| 
 | 
    97 			</xsl:if>
 | 
| 
 | 
    98 		</bug>
 | 
| 
1
 | 
    99 	</xsl:template>
 | 
| 
 | 
   100 
 | 
| 
4
 | 
   101 	<!-- output -->
 | 
| 
0
 | 
   102 	<xsl:template match="/">
 | 
| 
4
 | 
   103 		<xsl:apply-templates select="exsl:node-set($structure)/bug">
 | 
| 
 | 
   104 			<xsl:with-param name="indent" select="0" />
 | 
| 
 | 
   105 		</xsl:apply-templates>
 | 
| 
0
 | 
   106 	</xsl:template>
 | 
| 
 | 
   107 
 | 
| 
 | 
   108 	<xsl:template match="bug">
 | 
| 
 | 
   109 		<xsl:param name="indent" select="0" />
 | 
| 
4
 | 
   110 		<xsl:variable name="id" select="@id" />
 | 
| 
 | 
   111 		<xsl:variable name="details" select="$bugs[bug_id = $id]" />
 | 
| 
0
 | 
   112 		<xsl:call-template name="start-task">
 | 
| 
 | 
   113 			<xsl:with-param name="indent" select="$indent" />
 | 
| 
4
 | 
   114 			<xsl:with-param name="id" select="@id" />
 | 
| 
 | 
   115 			<xsl:with-param name="desc" select="$details/short_desc" />
 | 
| 
0
 | 
   116 		</xsl:call-template>
 | 
| 
 | 
   117 
 | 
| 
4
 | 
   118 		<xsl:for-each select="$details/*">
 | 
| 
 | 
   119 			<xsl:variable name="directive">
 | 
| 
 | 
   120 				<xsl:apply-templates select="." mode="task-details" />
 | 
| 
 | 
   121 			</xsl:variable>
 | 
| 
 | 
   122 			<xsl:if test="string($directive)">
 | 
| 
 | 
   123 				<xsl:call-template name="begin-line">
 | 
| 
 | 
   124 					<xsl:with-param name="indent" select="$indent + 1" />
 | 
| 
 | 
   125 				</xsl:call-template>
 | 
| 
 | 
   126 				<xsl:value-of select="$directive" />
 | 
| 
 | 
   127 				<xsl:call-template name="end-line" />
 | 
| 
 | 
   128 			</xsl:if>
 | 
| 
 | 
   129 		</xsl:for-each>
 | 
| 
0
 | 
   130 
 | 
| 
4
 | 
   131 		<xsl:apply-templates>
 | 
| 
 | 
   132 			<xsl:with-param name="indent" select="$indent + 1" />
 | 
| 
 | 
   133 		</xsl:apply-templates>
 | 
| 
0
 | 
   134 
 | 
| 
 | 
   135 		<xsl:call-template name="end-task">
 | 
| 
 | 
   136 			<xsl:with-param name="indent" select="$indent" />
 | 
| 
 | 
   137 		</xsl:call-template>
 | 
| 
 | 
   138 	</xsl:template>
 | 
| 
 | 
   139 
 | 
| 
4
 | 
   140 	<xsl:template match="estimated_time" mode="task-details">
 | 
| 
 | 
   141 		<xsl:if test="number(.)">
 | 
| 
 | 
   142 			<xsl:value-of select="concat('effort ', .,'h')" />
 | 
| 
 | 
   143 		</xsl:if>
 | 
| 
 | 
   144 	</xsl:template>
 | 
| 
 | 
   145 
 | 
| 
 | 
   146 	<xsl:template match="assigned_to" mode="task-details">
 | 
| 
 | 
   147 		<xsl:variable name="email" select="string(.)" />
 | 
| 
 | 
   148 		<xsl:variable name="resource" select="$resources[@email = $email]/@id" />
 | 
| 
 | 
   149 		<xsl:if test="$resource">
 | 
| 
 | 
   150 			<xsl:value-of select="concat('allocate ', $resource)" />
 | 
| 
 | 
   151 		</xsl:if>
 | 
| 
 | 
   152 	</xsl:template>
 | 
| 
 | 
   153 	<xsl:template match="text()" mode="task-details">
 | 
| 
 | 
   154 	</xsl:template>
 | 
| 
 | 
   155 
 | 
| 
 | 
   156 	<xsl:template match="depends">
 | 
| 
 | 
   157 		<xsl:param name="indent" select="0" />
 | 
| 
 | 
   158 		<xsl:call-template name="begin-line">
 | 
| 
 | 
   159 			<xsl:with-param name="indent" select="$indent" />
 | 
| 
 | 
   160 		</xsl:call-template>
 | 
| 
 | 
   161 		<xsl:text>depends </xsl:text>
 | 
| 
 | 
   162 		<xsl:apply-templates>
 | 
| 
 | 
   163 			<xsl:with-param name="referer" select=".." />
 | 
| 
 | 
   164 		</xsl:apply-templates>
 | 
| 
 | 
   165 		<xsl:call-template name="end-line" />
 | 
| 
 | 
   166 	</xsl:template>
 | 
| 
 | 
   167 
 | 
| 
 | 
   168 	<xsl:template match="depends/bug">
 | 
| 
 | 
   169 		<xsl:param name="referer" />
 | 
| 
 | 
   170 		<xsl:call-template name="bug-reference">
 | 
| 
 | 
   171 			<xsl:with-param name="id" select="@id" />
 | 
| 
 | 
   172 			<xsl:with-param name="referer" select="$referer" />
 | 
| 
 | 
   173 		</xsl:call-template>
 | 
| 
 | 
   174 		<xsl:if test="position() != last()">
 | 
| 
 | 
   175 			<xsl:text>, </xsl:text>
 | 
| 
 | 
   176 		</xsl:if>
 | 
| 
 | 
   177 	</xsl:template>
 | 
| 
 | 
   178 
 | 
| 
 | 
   179 
 | 
| 
 | 
   180 	<xsl:template match="text()" />
 | 
| 
 | 
   181 
 | 
| 
 | 
   182 
 | 
| 
 | 
   183 
 | 
| 
 | 
   184 	<xsl:template name="bug-local-name">
 | 
| 
 | 
   185 		<xsl:param name="id" />
 | 
| 
 | 
   186 		<xsl:value-of select="concat('bug',$id)" />
 | 
| 
 | 
   187 	</xsl:template>
 | 
| 
 | 
   188 
 | 
| 
 | 
   189 
 | 
| 
 | 
   190 	<xsl:template name="bug-reference">
 | 
| 
 | 
   191 		<xsl:param name="id" />
 | 
| 
 | 
   192 		<xsl:param name="referer" />
 | 
| 
 | 
   193 
 | 
| 
 | 
   194 		<xsl:variable name="refererPathFragment">
 | 
| 
 | 
   195 			<bug id="#root" />
 | 
| 
 | 
   196 			<xsl:for-each select="$referer/ancestor-or-self::bug">
 | 
| 
 | 
   197 				<bug id="{@id}" />
 | 
| 
 | 
   198 			</xsl:for-each>
 | 
| 
 | 
   199 		</xsl:variable>
 | 
| 
 | 
   200 		<xsl:variable name="targetPathFragment">
 | 
| 
 | 
   201 			<bug id="#root" />
 | 
| 
 | 
   202 			<xsl:for-each
 | 
| 
 | 
   203 				select="exsl:node-set($structure)//bug[local-name(..) != 'depends' and @id = $id]/ancestor-or-self::bug">
 | 
| 
 | 
   204 				<bug id="{@id}" />
 | 
| 
 | 
   205 			</xsl:for-each>
 | 
| 
 | 
   206 		</xsl:variable>
 | 
| 
 | 
   207 		<xsl:variable name="path"
 | 
| 
 | 
   208 			select="exsl:node-set($refererPathFragment)/bug" />
 | 
| 
 | 
   209 		<xsl:variable name="targetPath"
 | 
| 
 | 
   210 			select="exsl:node-set($targetPathFragment)/bug" />
 | 
| 
 | 
   211 
 | 
| 
 | 
   212 		<!-- find closest shared container id -->
 | 
| 
 | 
   213 		<xsl:variable name="join"
 | 
| 
 | 
   214 			select="($path[@id = $targetPath/@id])[position() = last() ]/@id" />
 | 
| 
 | 
   215 
 | 
| 
 | 
   216 		<!-- how many levels we need to up -->
 | 
| 
 | 
   217 		<xsl:variable name="depth"
 | 
| 
 | 
   218 			select="count($path[@id = $join]/following-sibling::node())" />
 | 
| 
 | 
   219 
 | 
| 
 | 
   220 		<!-- DEBUG -->
 | 
| 
 | 
   221 		<!-- <xsl:value-of select="concat('id=', $id, ',referer=', $referer/@id)" 
 | 
| 
 | 
   222 			/> <xsl:text>, path=</xsl:text> <xsl:for-each select="$targetPath"> <xsl:value-of 
 | 
| 
 | 
   223 			select="concat(name(),@id)" /> <xsl:if test="position() != last()"> <xsl:text>-</xsl:text> 
 | 
| 
 | 
   224 			</xsl:if> </xsl:for-each> -->
 | 
| 
 | 
   225 		<!-- DEBUG -->
 | 
| 
 | 
   226 		<!-- <xsl:value-of select="concat(', join=', $join,', depth=', $depth,' 
 | 
| 
 | 
   227 			')" /> -->
 | 
| 
 | 
   228 
 | 
| 
 | 
   229 		<!-- PRINT REFERENCE -->
 | 
| 
 | 
   230 		<xsl:call-template name="repeat">
 | 
| 
 | 
   231 			<xsl:with-param name="value" select="'!'" />
 | 
| 
 | 
   232 			<xsl:with-param name="count" select="$depth" />
 | 
| 
 | 
   233 		</xsl:call-template>
 | 
| 
 | 
   234 		<xsl:for-each select="$targetPath[@id = $join]/following-sibling::node()">
 | 
| 
 | 
   235 			<xsl:call-template name="bug-local-name">
 | 
| 
 | 
   236 				<xsl:with-param name="id" select="@id" />
 | 
| 
 | 
   237 			</xsl:call-template>
 | 
| 
 | 
   238 			<xsl:if test="position() != last()">
 | 
| 
 | 
   239 				<xsl:text>.</xsl:text>
 | 
| 
 | 
   240 			</xsl:if>
 | 
| 
 | 
   241 		</xsl:for-each>
 | 
| 
 | 
   242 
 | 
| 
0
 | 
   243 	</xsl:template>
 | 
| 
 | 
   244 
 | 
| 
 | 
   245 	<xsl:template name="start-task">
 | 
| 
 | 
   246 		<xsl:param name="indent" />
 | 
| 
4
 | 
   247 		<xsl:param name="id" />
 | 
| 
 | 
   248 		<xsl:param name="desc" />
 | 
| 
0
 | 
   249 		<xsl:call-template name="begin-line">
 | 
| 
 | 
   250 			<xsl:with-param name="indent" select="$indent" />
 | 
| 
 | 
   251 		</xsl:call-template>
 | 
| 
 | 
   252 		<xsl:text>task </xsl:text>
 | 
| 
4
 | 
   253 		<xsl:call-template name="bug-local-name">
 | 
| 
 | 
   254 			<xsl:with-param name="id" select="$id" />
 | 
| 
0
 | 
   255 		</xsl:call-template>
 | 
| 
4
 | 
   256 		<xsl:value-of select="concat(' "',$desc,'" {')" />
 | 
| 
0
 | 
   257 		<xsl:call-template name="end-line" />
 | 
| 
 | 
   258 	</xsl:template>
 | 
| 
 | 
   259 
 | 
| 
 | 
   260 	<xsl:template name="end-task">
 | 
| 
 | 
   261 		<xsl:param name="indent" />
 | 
| 
 | 
   262 		<xsl:call-template name="begin-line">
 | 
| 
 | 
   263 			<xsl:with-param name="indent" select="$indent" />
 | 
| 
 | 
   264 		</xsl:call-template>
 | 
| 
 | 
   265 		<xsl:text>}</xsl:text>
 | 
| 
 | 
   266 		<xsl:call-template name="end-line" />
 | 
| 
 | 
   267 	</xsl:template>
 | 
| 
 | 
   268 
 | 
| 
 | 
   269 	<xsl:template name="begin-line">
 | 
| 
 | 
   270 		<xsl:param name="indent" />
 | 
| 
 | 
   271 		<xsl:if test="number($indent) > 0">
 | 
| 
 | 
   272 			<xsl:text>    </xsl:text>
 | 
| 
 | 
   273 			<xsl:call-template name="begin-line">
 | 
| 
 | 
   274 				<xsl:with-param name="indent" select="$indent - 1" />
 | 
| 
 | 
   275 			</xsl:call-template>
 | 
| 
 | 
   276 		</xsl:if>
 | 
| 
 | 
   277 	</xsl:template>
 | 
| 
 | 
   278 	<xsl:template name="end-line">
 | 
| 
 | 
   279 		<xsl:text>
</xsl:text>
 | 
| 
 | 
   280 	</xsl:template>
 | 
| 
4
 | 
   281 
 | 
| 
 | 
   282 	<xsl:template name="repeat">
 | 
| 
 | 
   283 		<xsl:param name="value" />
 | 
| 
 | 
   284 		<xsl:param name="count" select="0" />
 | 
| 
 | 
   285 
 | 
| 
 | 
   286 		<xsl:if test="number($count)">
 | 
| 
 | 
   287 			<xsl:copy-of select="$value" />
 | 
| 
 | 
   288 			<xsl:call-template name="repeat">
 | 
| 
 | 
   289 				<xsl:with-param name="value" select="$value" />
 | 
| 
 | 
   290 				<xsl:with-param name="count" select="$count - 1" />
 | 
| 
 | 
   291 			</xsl:call-template>
 | 
| 
 | 
   292 		</xsl:if>
 | 
| 
 | 
   293 	</xsl:template>
 | 
| 
0
 | 
   294 </xsl:stylesheet> |