changeset 1:d1400de5832b

improved xsl
author cin
date Fri, 21 Aug 2015 20:07:52 +0300
parents 8cae44c166d3
children 14caabdb946b
files bug-list.xsl bug-list1.xml translate.pl
diffstat 3 files changed, 100 insertions(+), 11 deletions(-) [+]
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()" />
--- a/bug-list1.xml	Thu Aug 20 20:54:19 2015 +0300
+++ b/bug-list1.xml	Fri Aug 21 20:07:52 2015 +0300
@@ -1,4 +1,5 @@
 <?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
+<!DOCTYPE bugzilla SYSTEM "http://implab.org/bugzilla/page.cgi?id=bugzilla.dtd">
 
 <bugzilla version="4.4.4"
           urlbase="http://implab.org/bugzilla/"
--- a/translate.pl	Thu Aug 20 20:54:19 2015 +0300
+++ b/translate.pl	Fri Aug 21 20:07:52 2015 +0300
@@ -1,11 +1,25 @@
 #!/usr/bin/perl -w
 
-xalan( -IN => "bug-list2.xml", -XSL => "bug-list.xsl" );
+our @ClassPath = qw(
+  /usr/share/java/xalan-j2-serializer.jar
+  /usr/share/java/xalan-j2.jar
+  /usr/share/java/xerces-j2.jar
+  /usr/share/java/xml-commons-resolver.jar
+  .
+);
+
+xalan(
+	-IN          => "bug-list1.xml",
+	-XSL         => "bug-list.xsl",
+	-URIRESOLVER => "org.apache.xml.resolver.tools.CatalogResolver",
+	-ENTITYRESOLVER => "org.apache.xml.resolver.tools.CatalogResolver"
+);
 
 sub xalan {
 	my %params = @_;
-	
-	return system java => -cp => "/usr/share/java/xalan-j2-serializer.jar:/usr/share/java/xalan-j2.jar", "org.apache.xalan.xslt.Process", %params;
+	return system 'java',
+	  -cp => join( ':', @ClassPath ),
+	  "org.apache.xalan.xslt.Process", %params;
 }
 
 __END__
@@ -36,4 +50,4 @@
 
 =back
 
-=cut
\ No newline at end of file
+=cut