diff bug-list.xsl @ 1:d1400de5832b

improved xsl
author cin
date Fri, 21 Aug 2015 20:07:52 +0300
parents 8cae44c166d3
children 36ae3ec94442
line wrap: on
line diff
--- a/bug-list.xsl	Thu Aug 20 20:54:19 2015 +0300
+++ b/bug-list.xsl	Fri Aug 21 20:07:52 2015 +0300
@@ -1,16 +1,90 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <xsl:stylesheet version="1.0"
-	xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
-	<xsl:output method="text" />
-	<xsl:key name="bugs-key" match="bug" use="bug_id" />
-	<xsl:variable name="roots" select="bugzilla/bug[not(blocked[key('bugs-key',.)])]"/>
-		
+	xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:exsl="http://exslt.org/common">
+	<xsl:output method="xml" indent="yes" />
+	<xsl:key name="bugid" match="bug" use="bug_id" />
+	<xsl:variable name="roots"
+		select="bugzilla/bug[not(blocked[key('bugid',.)])]" />
+
+	<!-- BUILD BUG TREE -->
+	<xsl:variable name="tree">
+		<xsl:apply-templates mode="tree" select="$roots" />
+	</xsl:variable>
+
+	<xsl:template match="bug" mode="tree">
+		<xsl:element name="bug">
+			<xsl:attribute name="id"><xsl:value-of select="bug_id" /></xsl:attribute>
+			<xsl:if test="component = 'product'">
+				<xsl:attribute name="product"><xsl:value-of select="boolean(1)" /></xsl:attribute>
+			</xsl:if>
+			<xsl:for-each select="dependson">
+				<xsl:apply-templates mode="tree" select="key('bugid', .)" />
+			</xsl:for-each>
+		</xsl:element>
+	</xsl:template>
+
+	<!-- CALCULATE RELATIONS -->
+	<xsl:variable name="relations">
+		<xsl:apply-templates select="bugzilla/bug" mode="relations" />
+	</xsl:variable>
+
+	<xsl:template match="bug" mode="relations">
+		<xsl:variable name="bugid" select="string(bug_id)" />
+		<bug id="{$bugid}">
+			<xsl:apply-templates select="exsl:node-set($tree)//bug[@id = $bugid]"
+				mode="traverse-relations">
+			</xsl:apply-templates>
+		</bug>
+	</xsl:template>
+
+	<xsl:template match="bug" mode="traverse-relations">
+		<xsl:variable name="bugid" select="@id" />
+		<xsl:variable name="level" select="count(ancestor::node())" />
+		<path>
+			<xsl:for-each select="ancestor::node()">
+				<bug id="{@id}" product="{@product}"/>
+			</xsl:for-each>
+		</path>
+		<xsl:for-each select="ancestor::bug[@product]">
+			<xsl:variable name="rank" select="$level - position()" />
+			<rel container="{@id}" rank="{$rank}" level="{$level}"/>
+		</xsl:for-each>
+	</xsl:template>
+
+	<!-- CALCULATE STRUCTURE -->
+
+	<xsl:variable name="structure">
+		<xsl:apply-templates select="exsl:node-set($relations)"
+			mode="structure" />
+	</xsl:variable>
+
+	<xsl:template match="bug" mode="structure">
+		<xsl:variable name="parent"
+			select="rel[ not(../rel/@rank &lt; @rank) ][1]/@container" />
+		<bug id="{@id}" container="{$parent}" />
+	</xsl:template>
+
+	<!-- -->
 	<xsl:template match="/">
-		<xsl:apply-templates select="$roots"/>
+		<root>
+			<xsl:copy-of select="$tree" />
+			<xsl:copy-of select="$relations" />
+			<xsl:copy-of select="$structure" />
+		</root>
 	</xsl:template>
 
 	<xsl:template match="bug">
-		<xsl:call-template name="bug-template" />
+		<xsl:value-of select="bug_id" />
+		<xsl:text>&#xa;</xsl:text>
+	</xsl:template>
+
+	<xsl:template match="bug[component = 'product']">
+		<xsl:value-of select="bug_id" />
+		<xsl:text>:&#xa;</xsl:text>
+		<xsl:for-each select="dependson">
+			<xsl:apply-templates select="key('bugid', .)" />
+		</xsl:for-each>
+		<xsl:text>---END---&#xa;</xsl:text>
 	</xsl:template>
 
 	<xsl:template match="text()" />