Debian Codegraph @

xsl/xccdf-report.xsl

raw symbols SCIP
1 <?xml version="1.0" encoding="utf-8" ?>
2
3 <!--
4 Copyright 2010-2014 Red Hat Inc., Durham, North Carolina.
5 All Rights Reserved.
6
7 This library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Lesser General Public
9 License as published by the Free Software Foundation; either
10 version 2.1 of the License, or (at your option) any later version.
11
12 This library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Lesser General Public License for more details.
16
17 You should have received a copy of the GNU Lesser General Public
18 License along with this library; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20
21 Authors:
22 Martin Preisler <[email protected]>
23 Lukas Kuklinek <[email protected]>
24 -->
25
26 <!--
27 This stylesheet is the entry point for HTML report generator.
28
29 The goal is to negotiate the right namespace and find the XPaths for TestResult
30 and Benchmark. All the logic to do that should be in this stylesheet and this
31 stylesheet only.
32 -->
33
34 <xsl:stylesheet version="1.1"
35 xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
36 xmlns:cdf="http://checklists.nist.gov/xccdf/1.2"
37 xmlns:exsl="http://exslt.org/common"
38 xmlns:s="http://open-scap.org/"
39 exclude-result-prefixes="xsl cdf s exsl">
40
41 <xsl:include href="xccdf-report-impl.xsl" />
42
43 <!-- parameters -->
44 <xsl:param name="testresult_id"/>
45 <xsl:param name="benchmark_id"/>
46
47 <!-- OVAL and SCE result parameters -->
48 <xsl:param name='pwd'/>
49 <xsl:param name='oval-template'/>
50 <xsl:param name='sce-template'/>
51
52 <xsl:variable name='oval-tmpl'>
53 <xsl:choose>
54 <xsl:when test='not($oval-template)' />
55 <xsl:when test='substring($oval-template, 1, 1) = "/"'><xsl:value-of select='$oval-template'/></xsl:when>
56 <xsl:otherwise><xsl:value-of select='concat($pwd, "/", $oval-template)'/></xsl:otherwise>
57 </xsl:choose>
58 </xsl:variable>
59
60 <xsl:variable name='sce-tmpl'>
61 <xsl:choose>
62 <xsl:when test='not($sce-template)' />
63 <xsl:when test='substring($sce-template, 1, 1) = "/"'><xsl:value-of select='$sce-template'/></xsl:when>
64 <xsl:otherwise><xsl:value-of select='concat($pwd, "/", $sce-template)'/></xsl:otherwise>
65 </xsl:choose>
66 </xsl:variable>
67
68 <!-- keys -->
69 <xsl:key name="items" match="cdf:Group|cdf:Rule|cdf:Value" use="@id"/>
70 <xsl:key name="profiles" match="cdf:Profile" use="@id"/>
71
72 <!-- main(..) -->
73 <xsl:template match="/">
74 <xsl:variable name='end_times'>
75 <s:times>
76 <xsl:for-each select='//cdf:TestResult/@end-time'>
77 <xsl:sort order='descending'/>
78 <s:t t='{.}'/>
79 </xsl:for-each>
80 </s:times>
81 </xsl:variable>
82
83 <xsl:variable name="last_test_time" select="exsl:node-set($end_times)/s:times/s:t[1]/@t"/>
84
85 <xsl:variable name="final_result_id">
86 <xsl:choose>
87 <xsl:when test="$testresult_id">
88 <xsl:value-of select="$testresult_id"/>
89 </xsl:when>
90 <xsl:otherwise>
91 <xsl:value-of select="//cdf:TestResult[@end-time=$last_test_time][last()]/@id"/>
92 </xsl:otherwise>
93 </xsl:choose>
94 </xsl:variable>
95
96 <xsl:variable name="final_benchmark_id">
97 <xsl:choose>
98 <xsl:when test="$benchmark_id">
99 <xsl:value-of select="$benchmark_id"/>
100 </xsl:when>
101 <xsl:otherwise>
102 <xsl:choose>
103 <xsl:when test="//cdf:TestResult[@id=$final_result_id][last()]/cdf:benchmark/@id">
104 <xsl:value-of select="//cdf:TestResult[@id=$final_result_id][last()]/cdf:benchmark/@id"/>
105 </xsl:when>
106 <xsl:otherwise>
107 <xsl:value-of select="//cdf:Benchmark[1]/@id"/>
108 </xsl:otherwise>
109 </xsl:choose>
110 </xsl:otherwise>
111 </xsl:choose>
112 </xsl:variable>
113
114 <xsl:variable name="testresult" select="//cdf:TestResult[@id=$final_result_id]"/>
115 <xsl:variable name="benchmark" select="//cdf:Benchmark[@id=$final_benchmark_id]"/>
116
117 <xsl:if test="not($testresult)">
118 <xsl:choose>
119 <xsl:when test="$testresult_id">
120 <xsl:message terminate="yes">No such cdf:TestResult exists (with @id = "<xsl:value-of select="$testresult_id"/>")</xsl:message>
121 </xsl:when>
122 <xsl:otherwise>
123 <xsl:message terminate="yes">No cdf:TestResult ID specified and no suitable candidate was autodetected.</xsl:message>
124 </xsl:otherwise>
125 </xsl:choose>
126 </xsl:if>
127
128 <xsl:if test="not($benchmark)">
129 <xsl:choose>
130 <xsl:when test="$benchmark_id">
131 <xsl:message terminate="yes">No such cdf:Benchmark exists (with @id = "<xsl:value-of select="$benchmark_id"/>")</xsl:message>
132 </xsl:when>
133 <xsl:otherwise>
134 <xsl:message terminate="yes">No cdf:Benchmark ID specified and no suitable candidate has been autodetected.</xsl:message>
135 </xsl:otherwise>
136 </xsl:choose>
137 </xsl:if>
138
139 <xsl:if test="$verbosity">
140 <xsl:message>TestResult ID: <xsl:value-of select="$final_result_id"/></xsl:message>
141 <xsl:message>Benchmark ID: <xsl:value-of select="$final_benchmark_id"/></xsl:message>
142 </xsl:if>
143
144 <xsl:call-template name="generate-report">
145 <xsl:with-param name="testresult" select="$testresult"/>
146 <xsl:with-param name="benchmark" select="$benchmark"/>
147 </xsl:call-template>
148 </xsl:template>
149
150 </xsl:stylesheet>