I tried to convert XML file into HTML using XSLT format but i got an error
RROR: 'Namespace prefix 'vuln' is undeclared.'
FATAL ERROR: 'Could not compile stylesheet'
The XML file started with
<?xml version='1.0' encoding='UTF-8'?>
<?xml-stylesheet type="text/xsl" version ="2.0" href="nvdXSLT.xsl"?>
<nvd xmlns:cpe-lang="http://cpe.mitre.org/language/2.0"
xmlns:scapcore="http://scap.nist.gov/schema/scap-core/0.1"
xmlns:vuln="http://scap.nist.gov/schema/vulnerability/0.4"
xmlns:cvss="http://scap.nist.gov/schema/cvss-v2/0.2"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:patch="http://scap.nist.gov/schema/patch/0.1"
xmlns="http://scap.nist.gov/schema/feed/vulnerability/2.0" >
<entry id="CVE-2007-5333">
<vuln:vulnerable-software-list>
<vuln:product>cpe:/a:apache_software_foundation:tomcat:4.1.34</vuln:product>
<vuln:product>cpe:/a:apache_software_foundation:tomcat:4.1.37</vuln:product>
<vuln:product>cpe:/a:apache:tomcat:4.1.24</vuln:product>
<vuln:product>cpe:/a:apache:tomcat:5.5.5</vuln:product>
<vuln:product>cpe:/a:apache:tomcat:5.5.2</vuln:product>
</vuln:vulnerable-software-list>
<vuln:cve-id>CVE-2007-5333</vuln:cve-id>
<vuln:published-datetime>2008-02-11T20:00:00.000-05:00</vuln:published-datetime>
<vuln:last-modified-datetime>2014-03-15T23:16:41.310-04:00</vuln:last-modified-datetime>
</entry>
</nvd>
And i created XSL transformer to transform the xml content into organized format and display the output on html format javax.xml.transform API. The XSL file as follow:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:vuln="http://scap.nist.gov/schema/vulnerability/0.4"
xmlns:cvss="http://scap.nist.gov/schema/cvss-v2/0.2"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:patch="http://scap.nist.gov/schema/patch/0.1"
xmlns="http://scap.nist.gov/schema/feed/vulnerability/2.0">
<xsl:output method="html" encoding="UTF-8" indent="yes"/>
<xsl:template match="/">
<!-- TODO: Auto-generated template -->
<html>
<body>
<h1>Parsing NVD XML file</h1>
<table border="1">
<tr>
<th>hasAffectedProducts</th>
</tr>
<xsl:for-each select="nvd/entry">
<tr>
<td><xsl:for-each select="/vuln:vulnerable-software-list"><xsl:value-of select="vuln:product" /></xsl:for-each></td>
</tr>
<td><xsl:value-of select="vuln:cve-id" /></td>
<td><xsl:value-of select="vuln:published-datetime" /></td>
<td><xsl:value-of select="vuln:last-modified-datetime"/></td>
.....
The JAVA API that I used to do transformation
public void transform(String dataXML, String inputXSL, String outputHTML)
throws TransformerConfigurationException, TransformerException {
TransformerFactory factory = TransformerFactory.newInstance();
StreamSource xslStream = new StreamSource(inputXSL);
Transformer transformer = factory.newTransformer(xslStream);
StreamSource in = new StreamSource(dataXML);
StreamResult out = new StreamResult(outputHTML);
transformer.transform(in, out);
System.out.println("The generated HTML file is:" + outputHTML);
}
Simply, received XML file and XSL file and create output file int HTML format.
vulnprefix without declaring it. XSLT can only operate on namespace-well-formed XML so you need to get the XML fixed at source to declare its namespaces properly. - Ian Roberts