Dies ist mit Can XSLT be improved further? verknüpft.XSLT-Verbesserung
Ich habe eine XML wie folgt:
XML-Beispiel
<?xml version="1.0" encoding="UTF-8"?>
<Benchmark xmlns="http://checklists.nist.gov/xccdf/1.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" id="xccdf_com.vmware.linux_benchmark_file-test" resolved="1" xml:lang="en-US">
<status date="2015-09-20">draft</status>
<title xmlns:xhtml="http://www.w3.org/1999/xhtml" xml:lang="en-US">Test content for file_test probe</title>
<description xmlns:xhtml="http://www.w3.org/1999/xhtml" xml:lang="en-US">File content for OVAL file file_test_content-oval.xml built on 2015-09-20T02:13:56</description>
<platform idref="cpe:/o:sles11:linux"/>
<version>v0.0</version>
<model system="urn:xccdf:scoring:default"/>
<Profile id="xccdf_com.vmware.linux_profile_test">
<status date="2015-09-20">draft</status>
<version update="1" time="2015-09-20T14:57:39.808+05:30">1.0</version>
<title xmlns:xhtml="http://www.w3.org/1999/xhtml" xml:lang="en-US">Test_Profile</title>
<description xmlns:xhtml="http://www.w3.org/1999/xhtml" xml:lang="en">This is a test profile to test file_test probe.</description>
<select idref="xccdf_com.vmware.linux_rule_test-def-3" selected="true"/>
<select idref="xccdf_com.vmware.linux_rule_test-def-2" selected="true"/>
<select idref="xccdf_com.vmware.linux_rule_test-def-1" selected="true"/>
</Profile>
<Group id="xccdf_com.vmware.linux_group_test" weight="1.000000">
<platform idref="cpe:/o:sles11:linux"/>
<Rule id="xccdf_com.vmware.linux_rule_test-def-3" selected="true" weight="1.000000" role="full" severity="unknown">
<title xmlns:xhtml="http://www.w3.org/1999/xhtml" xml:lang="en-US">Rule 3 - /etc/passwd file is group-owned by root</title>
<description xmlns:xhtml="http://www.w3.org/1999/xhtml" xml:lang="en-US">This rule verifies that /etc/passwd file is group-owned by root.</description>
<check system="http://oval.mitre.org/XMLSchema/oval-definitions-5">
<check-content-ref name="oval:com.vmware.test.linux:def:3" href="file_test_content-oval.xml"/>
</check>
</Rule>
<Rule id="xccdf_com.vmware.linux_rule_test-def-2" selected="true">
<title xmlns:xhtml="http://www.w3.org/1999/xhtml" xml:lang="en-US">Rule 2 - /etc/passwd file is owned by root</title>
<description xmlns:xhtml="http://www.w3.org/1999/xhtml" xml:lang="en-US">This rule verifies that /etc/passwd file is owned by root.</description>
<check system="http://oval.mitre.org/XMLSchema/oval-definitions-5">
<check-content-ref name="oval:com.vmware.test.linux:def:2" href="file_test_content-oval.xml"/>
</check>
</Rule>
<Rule id="xccdf_com.vmware.linux_rule_test-def-1" selected="true">
<title xmlns:xhtml="http://www.w3.org/1999/xhtml" xml:lang="en-US">Rule 1 - /etc/passwd file has permissions of 644 or more restrictive</title>
<description xmlns:xhtml="http://www.w3.org/1999/xhtml" xml:lang="en-US">This rule verifies that /etc/passwd file has permissions of 644 or more restrictive.</description>
<check system="http://oval.mitre.org/XMLSchema/oval-definitions-5">
<check-content-ref name="oval:com.vmware.test.linux:def:1" href="file_test_content-oval.xml"/>
</check>
</Rule>
</Group>
<TestResult id="xccdf_org.open-scap_testresult_xccdf_com.vmware.linux_profile_test" start-time="2016-08-17T13:38:29" end-time="2016-08-17T13:38:29" version="v0.0">
<benchmark href="/tmp/tmp.VnFIMSRKhw/input.xml" id="xccdf_com.vmware.linux_benchmark_file-test"/>
<title>OSCAP Scan Result</title>
<identity authenticated="false" privileged="false"/>
<profile idref="xccdf_com.vmware.linux_profile_test"/>
<target>vROPS_6-1</target>
<target-address>127.0.0.1</target-address>
<target-address>127.0.0.2</target-address>
<target-address>10.112.56.130</target-address>
<target-address>0:0:0:0:0:0:0:1</target-address>
<target-address>fe80:0:0:0:250:56ff:fe93:6159</target-address>
<target-address>0:0:0:0:0:0:0:10.112.56.130</target-address>
<target-address>0:0:0:0:0:0:0:127.0.0.2</target-address>
<target-address>0:0:0:0:0:0:0:127.0.0.1</target-address>
<target-facts>
<fact name="urn:xccdf:fact:scanner:name" type="string">OpenSCAP</fact>
<fact name="urn:xccdf:fact:scanner:version" type="string">1.2.5</fact>
<fact name="urn:xccdf:fact:ethernet:MAC" type="string">00:00:00:00:00:00</fact>
<fact name="urn:xccdf:fact:ethernet:MAC" type="string">00:00:00:00:00:00</fact>
<fact name="urn:xccdf:fact:ethernet:MAC" type="string">00:50:56:93:61:59</fact>
<fact name="urn:xccdf:fact:ethernet:MAC" type="string">00:00:00:00:00:00</fact>
<fact name="urn:xccdf:fact:ethernet:MAC" type="string">00:50:56:93:61:59</fact>
<fact name="urn:xccdf:fact:ethernet:MAC" type="string">00:00:00:00:00:00</fact>
<fact name="urn:xccdf:fact:ethernet:MAC" type="string">00:00:00:00:00:00</fact>
<fact name="urn:xccdf:fact:ethernet:MAC" type="string">00:00:00:00:00:00</fact>
</target-facts>
<platform idref="cpe:/o:sles11:linux"/>
<rule-result idref="xccdf_com.vmware.linux_rule_test-def-3" role="full" time="2016-08-17T13:38:29" severity="unknown" weight="1.000000">
<result>pass</result>
<check system="http://oval.mitre.org/XMLSchema/oval-definitions-5">
<check-content-ref name="oval:com.vmware.test.linux:def:3" href="file_test_content-oval.xml"/>
</check>
</rule-result>
<rule-result idref="xccdf_com.vmware.linux_rule_test-def-2" time="2016-08-17T13:38:29" weight="1.000000">
<result>pass</result>
<check system="http://oval.mitre.org/XMLSchema/oval-definitions-5">
<check-content-ref name="oval:com.vmware.test.linux:def:2" href="file_test_content-oval.xml"/>
</check>
</rule-result>
<rule-result idref="xccdf_com.vmware.linux_rule_test-def-1" time="2016-08-17T13:38:29" weight="1.000000">
<result>pass</result>
<check system="http://oval.mitre.org/XMLSchema/oval-definitions-5">
<check-content-ref name="oval:com.vmware.test.linux:def:1" href="file_test_content-oval.xml"/>
</check>
</rule-result>
<score system="urn:xccdf:scoring:default" maximum="100.000000">100.000000</score>
</TestResult>
</Benchmark>
Bitte beachten Sie, dass Gruppen und Profilelement sind optional. Ein gültiger Probe xml könnte man sein, wie unten auch:
<?xml version="1.0" encoding="UTF-8"?>
<Benchmark xmlns="http://checklists.nist.gov/xccdf/1.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" id="xccdf_com.vmware.linux_benchmark_file-test" resolved="1" xml:lang="en-US">
<status date="2015-09-20">draft</status>
<title xmlns:xhtml="http://www.w3.org/1999/xhtml" xml:lang="en-US">Test content for file_test probe</title>
<description xmlns:xhtml="http://www.w3.org/1999/xhtml" xml:lang="en-US">File content for OVAL file file_test_content-oval.xml built on 2015-09-20T02:13:56</description>
<platform idref="cpe:/o:sles11:linux"/>
<version>v0.0</version>
<model system="urn:xccdf:scoring:default"/>
<Rule id="xccdf_com.vmware.linux_rule_test-def-3" selected="true" weight="1.000000" role="full" severity="unknown">
<title xmlns:xhtml="http://www.w3.org/1999/xhtml" xml:lang="en-US">Rule 3 - /etc/passwd file is group-owned by root</title>
<description xmlns:xhtml="http://www.w3.org/1999/xhtml" xml:lang="en-US">This rule verifies that /etc/passwd file is group-owned by root.</description>
<check system="http://oval.mitre.org/XMLSchema/oval-definitions-5">
<check-content-ref name="oval:com.vmware.test.linux:def:3" href="file_test_content-oval.xml"/>
</check>
</Rule>
<Rule id="xccdf_com.vmware.linux_rule_test-def-2" selected="true">
<title xmlns:xhtml="http://www.w3.org/1999/xhtml" xml:lang="en-US">Rule 2 - /etc/passwd file is owned by root</title>
<description xmlns:xhtml="http://www.w3.org/1999/xhtml" xml:lang="en-US">This rule verifies that /etc/passwd file is owned by root.</description>
<check system="http://oval.mitre.org/XMLSchema/oval-definitions-5">
<check-content-ref name="oval:com.vmware.test.linux:def:2" href="file_test_content-oval.xml"/>
</check>
</Rule>
<Rule id="xccdf_com.vmware.linux_rule_test-def-1" selected="true">
<title xmlns:xhtml="http://www.w3.org/1999/xhtml" xml:lang="en-US">Rule 1 - /etc/passwd file has permissions of 644 or more restrictive</title>
<description xmlns:xhtml="http://www.w3.org/1999/xhtml" xml:lang="en-US">This rule verifies that /etc/passwd file has permissions of 644 or more restrictive.</description>
<check system="http://oval.mitre.org/XMLSchema/oval-definitions-5">
<check-content-ref name="oval:com.vmware.test.linux:def:1" href="file_test_content-oval.xml"/>
</check>
</Rule>
<TestResult id="xccdf_org.open-scap_testresult_default-profile" start-time="2016-08-17T19:18:42" end-time="2016-08-17T19:18:42" version="v0.0">
<benchmark href="/tmp/tmp.nMXPWBmAJO/input.xml" id="xccdf_com.vmware.linux_benchmark_file-test"/>
<title>OSCAP Scan Result</title>
<identity authenticated="false" privileged="false"/>
<target>vRealizeClusterNode</target>
<target-address>127.0.0.1</target-address>
<target-address>127.0.0.2</target-address>
<target-address>10.112.56.132</target-address>
<target-address>0:0:0:0:0:0:0:1</target-address>
<target-address>fe80:0:0:0:250:56ff:fe93:21b6</target-address>
<target-facts>
<fact name="urn:xccdf:fact:scanner:name" type="string">OpenSCAP</fact>
<fact name="urn:xccdf:fact:scanner:version" type="string">1.2.5</fact>
<fact name="urn:xccdf:fact:ethernet:MAC" type="string">00:00:00:00:00:00</fact>
<fact name="urn:xccdf:fact:ethernet:MAC" type="string">00:00:00:00:00:00</fact>
<fact name="urn:xccdf:fact:ethernet:MAC" type="string">00:50:56:93:21:B6</fact>
<fact name="urn:xccdf:fact:ethernet:MAC" type="string">00:00:00:00:00:00</fact>
<fact name="urn:xccdf:fact:ethernet:MAC" type="string">00:50:56:93:21:B6</fact>
</target-facts>
<platform idref="cpe:/o:sles11:linux"/>
<rule-result idref="xccdf_com.vmware.linux_rule_test-def-3" role="full" time="2016-08-17T19:18:42" severity="unknown" weight="1.000000">
<result>pass</result>
<check system="http://oval.mitre.org/XMLSchema/oval-definitions-5">
<check-content-ref name="oval:com.vmware.test.linux:def:3" href="file_test_content-oval.xml"/>
</check>
</rule-result>
<rule-result idref="xccdf_com.vmware.linux_rule_test-def-2" time="2016-08-17T19:18:42" weight="1.000000">
<result>pass</result>
<check system="http://oval.mitre.org/XMLSchema/oval-definitions-5">
<check-content-ref name="oval:com.vmware.test.linux:def:2" href="file_test_content-oval.xml"/>
</check>
</rule-result>
<rule-result idref="xccdf_com.vmware.linux_rule_test-def-1" time="2016-08-17T19:18:42" weight="1.000000">
<result>pass</result>
<check system="http://oval.mitre.org/XMLSchema/oval-definitions-5">
<check-content-ref name="oval:com.vmware.test.linux:def:1" href="file_test_content-oval.xml"/>
</check>
</rule-result>
<score system="urn:xccdf:scoring:default" maximum="100.000000">100.000000</score>
</TestResult>
</Benchmark>
Ich bin an idref
Aufnehmen und title
und result
von den beiden oben möglich xmls entspricht.
Der Ausgang könnte einfach nur durch \n
getrennt Text sein.
schrieb ich XSL wie folgt:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:cdf="http://checklists.nist.gov/xccdf/1.2"
xmlns:exsl="http://exslt.org/common"
xmlns:db="http://docbook.org/ns/docbook"
xmlns:xlink="http://www.w3.org/1999/xlink"
xmlns="http://docbook.org/ns/docbook"
xmlns:s="http://open-scap.org/"
exclude-result-prefixes="xsl cdf db s exsl"
xmlns:ovalres="http://oval.mitre.org/XMLSchema/oval-results-5"
xmlns:sceres="http://open-scap.org/page/SCE_result_file"
>
<xsl:output method="text" encoding="utf-8" />
<xsl:key name="result" match="cdf:rule-result" use="@idref" />
<xsl:template match="/cdf:TestResult">
<xsl:for-each select="cdf:rule-result">
<xsl:value-of select="@idref" />
<xsl:text>
</xsl:text>
<xsl:value-of select="cdf:title"/>
<xsl:text>
</xsl:text>
<xsl:value-of select="key('result', @idref)/result"/>
<xsl:text>
</xsl:text>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
Aber dies ist die gewünschte Ausgabe nicht zu erzeugen? Was mache ich hier falsch?
Bitte helfen.
Warum beginnen Sie bei 'TestResult/rule-result' und nicht bei' Group/Rule' - wie in der vorherigen Frage? Wenn Sie die Werte von 'rule-result' direkt auflisten können, müssen Sie den Schlüssel nicht verwenden. –
Und wo ist dein erwartetes Ergebnis? –