我需要一些帮助将 XML 文件转换为 CSV。
这是我的 XML 文件的摘录:
<?xml version='1.0' encoding='UTF-8'?>
<nvd xmlns:cvss="http://scap.nist.gov/schema/cvss-v2/0.2" xmlns:cpe-lang="http://cpe.mitre.org/language/2.0" xmlns:vuln="http://scap.nist.gov/schema/vulnerability/0.4" xmlns="http://scap.nist.gov/schema/feed/vulnerability/2.0" xmlns:patch="http://scap.nist.gov/schema/patch/0.1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:scap-core="http://scap.nist.gov/schema/scap-core/0.1" nvd_xml_version="2.0" pub_date="2013-04-12T12:00:30" xsi:schemaLocation="http://scap.nist.gov/schema/patch/0.1 http://nvd.nist.gov/schema/patch_0.1.xsd http://scap.nist.gov/schema/scap-core/0.1 http://nvd.nist.gov/schema/scap-core_0.1.xsd http://scap.nist.gov/schema/feed/vulnerability/2.0 http://nvd.nist.gov/schema/nvd-cve-feed_2.0.xsd">
<entry id="CVE-2012-5048">
<vuln:vulnerable-configuration id="http://nvd.nist.gov/">
<cpe-lang:logical-test negate="false" operator="OR">
<cpe-lang:fact-ref name="cpe:/a:optimalog:optima_plc:1.5.2"/>
<cpe-lang:fact-ref name="cpe:/a:optimalog:optima_plc:1.5.1"/>
</cpe-lang:logical-test>
</vuln:vulnerable-configuration>
<vuln:vulnerable-software-list>
<vuln:product>cpe:/a:optimalog:optima_plc:1.4.10</vuln:product>
<vuln:product>cpe:/a:optimalog:optima_plc:1.5.0</vuln:product>
</vuln:vulnerable-software-list>
<vuln:cve-id>CVE-2012-5048</vuln:cve-id>
<vuln:published-datetime>2012-09-28T06:40:22.507-04:00</vuln:published-datetime>
<vuln:last-modified-datetime>2013-04-10T23:31:27.227-04:00</vuln:last-modified-datetime>
<vuln:cvss>
<cvss:base_metrics>
<cvss:score>7.8</cvss:score>
<cvss:access-vector>NETWORK</cvss:access-vector>
</cvss:base_metrics>
</vuln:cvss>
<vuln:cwe id="CWE-399"/>
<vuln:references xml:lang="en" reference_type="UNKNOWN">
<vuln:source>MISC</vuln:source>
<vuln:reference href="http://www.us-cert.gov" xml:lang="en">http://www.us-cert.gov</vuln:reference>
</vuln:references>
<vuln:references xml:lang="en" reference_type="UNKNOWN">
<vuln:source>BID</vuln:source>
<vuln:reference href="http://www.securityfocus.com/bid/55712" xml:lang="en">55712</vuln:reference>
</vuln:references>
<vuln:summary>APIFTP Server</vuln:summary>
</entry>
</nvd>
您将在下面找到我尝试过的 XSLT 文件,但它无法正常工作,因为它不会(例如)将 cvss:score 和 cvss:access-vector 写入不同的列。谁能帮我将 XML 文件的所有条目写入不同的列?
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text" encoding="iso-8859-1"/>
<xsl:strip-space elements="*" />
<xsl:template match="/*/child::*">
<xsl:for-each select="child::*">
<xsl:if test="position() != last()"><xsl:value-of select="normalize-space(.)"/>,</xsl:if>
<xsl:if test="position() = last()"><xsl:value-of select="normalize-space(.)"/><xsl:text>
</xsl:text>
</xsl:if>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>