File: addToSummary.xsl

package info (click to toggle)
libgroboutils-java 5-3
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 9,396 kB
  • ctags: 11,186
  • sloc: java: 59,748; xml: 12,762; sh: 377; perl: 104; makefile: 20
file content (148 lines) | stat: -rw-r--r-- 4,238 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet xmlns:xsl='http://www.w3.org/1999/XSL/Transform' version='1.0'>
    <xsl:output
        method="xml"
        indent="yes"
        standalone="yes"
        encoding="ISO-8859-1" />

<!--
Two inputs: summary.xml (generated) and input-summary.xml (per-project)

    summary.xml format:
        <set>
            <project-id name="name" dir="dir" />
            <type name="name">
                <subproject name="name" version="version">
                    ...
                </subproject>
            </type>
        </set>
    
    input-summary.xml format:
        <list>
            <category name="name">
                <project>
                ...
                </project>
            </category>
        </list>
-->
        
        
<xsl:param name="projectname">[error]</xsl:param>
<xsl:param name="projectversion">0.0</xsl:param>
<xsl:variable name="summary" select="document('input-summary.xml')"/>

    
    <!-- base document
    <xsl:template match="/" >
        <xsl:message terminate="no">
        Found root.
        </xsl:message>
        
        <xsl:apply-templates />
    </xsl:template >
    -->
    
    <xsl:template match="set" >
        <xsl:message terminate="no">
        Found list.
        </xsl:message>
        
        <set>
            <xsl:apply-templates />
            
            <xsl:for-each
                select="$summary//list/category[position()=1]/project[position()=1]" >
                <project-id>
                    <xsl:attribute name="name"><xsl:value-of
                    select="$projectname" /></xsl:attribute>
                    <xsl:attribute name="dir"><xsl:value-of
                    select="name/text()" /></xsl:attribute>
                </project-id>
                
            </xsl:for-each>
        </set>
    </xsl:template>
    
    
    <xsl:template match="project-id" >
        <xsl:message terminate="no">
        Found project-id '<xsl:value-of select="@name"/>'.
        </xsl:message>
        <xsl:if test="@name != $projectname" >
            <project-id>
                <xsl:copy-of select="./@*" />
            </project-id>
        </xsl:if>
    </xsl:template>

    
    
    <xsl:template match="type" >
        <xsl:variable name="cname" select="@name" />

        <xsl:message terminate="no">
        Found type '<xsl:value-of select="$cname"/>'.
        </xsl:message>
   
        <type>
        <xsl:copy-of select="./@*" />
        
        <xsl:apply-templates />
        
        
        <xsl:apply-templates select="$summary//list/category" >
            <xsl:with-param name="catname" select="$cname" />
        </xsl:apply-templates>
        </type>
    </xsl:template>
    
    
    <!-- input-summary.xml file -->
    <xsl:template match="category" >
        <xsl:param name="catname" select="'unknown'" />
        
        <xsl:message terminate="no">
        Found input summary category '<xsl:value-of select="@name" />'.
        (owning type is '<xsl:value-of select="$catname" />')
        </xsl:message>
        <xsl:if test="@name = $catname" >
        <!-- add this project to the list -->
            <xsl:apply-templates />
        </xsl:if>
    </xsl:template>
   
    
    <!-- summary.xml: Copy all the text -->
    <xsl:template match="subproject" >
        <!-- do not copy the project in question -->
        <xsl:if test="not( @name = string($projectname) )">
        <subproject>
            <xsl:copy-of select="./@*" />
            
            <xsl:apply-templates />
        </subproject>
        </xsl:if>
    </xsl:template>
    
    
    <!-- input-summary.xml: translate and copy -->
    <xsl:template match="project" >
        <subproject>
            <xsl:attribute name="name"><xsl:value-of
                select="$projectname"/></xsl:attribute>
            <xsl:attribute name="version"><xsl:value-of
                select="$projectversion"/></xsl:attribute>
    
            <xsl:apply-templates />
        </subproject>
    </xsl:template>

    <xsl:template match="@*|node()" name="CopyWithTemplates">
        <xsl:copy>
            <xsl:apply-templates select="@*|node()" />
        </xsl:copy>
    </xsl:template>
</xsl:stylesheet>