vendredi 30 janvier 2015

XSL: Group parent attributes using matching child attribute


Vote count:

0




Hey guys I'm trying to use transform an XML document to output a table directly into excel. The problem I'm having is I need to group elements by a child node. My current XSLT is this:



<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://ift.tt/tCZ8VR">

<xsl:template match="ScanData">
<html>
<body>
<xsl:for-each select="Report/ReportHost">
<xsl:if test="ReportItem/@severity &gt; 0">
<h2><xsl:value-of select="@name"/></h2><br/>
</xsl:if>
<xsl:for-each select="ReportItem">
<xsl:sort select = "@severity" data-type="number" order="descending"/>
<xsl:sort select = "@pluginID"/>
<xsl:if test="@severity &gt; 0">
<xsl:if test="(preceding-sibling::*[1]/@pluginName != @pluginName)">
<b>Severity: </b><xsl:value-of select="@severity"/><br/>
<b>Name: </b><xsl:value-of select="@pluginName"/><br/>
<b>Synopsis: </b><xsl:value-of select="synopsis"/><br/>
<b>Description: </b><xsl:value-of select="description"/><br/>
<b>Solution: </b><xsl:value-of select="solution"/><br/>
</xsl:if>
Port:<xsl:value-of select="@protocol"/>/<xsl:value-of select="@port"/><br/>
</xsl:if>
</xsl:for-each>
</xsl:for-each>
</body>
</html>
</xsl:template>
</xsl:stylesheet>


Sample XML



<?xml version="1.0" ?>
<?xml-stylesheet type="text/xsl" href="Internal.xsl"?>
<ScanData>
<Report name="Report">
<ReportHost name="192.168.1.1">
<ReportItem port="0" svc_name="general" protocol="tcp" severity="1" pluginID="11936" pluginName="OS Identification" pluginFamily="General">
<description>Using a combination of remote probes (TCP/IP, SMB, HTTP, NTP, SNMP, etc...), it is possible to guess the name of the remote operating system in use. It is also sometimes possible to guess the version of the operating system.</description>
<fname>os_fingerprint.nasl</fname>
<plugin_modification_date>2014/02/19</plugin_modification_date>
<plugin_name>OS Identification</plugin_name>
<plugin_publication_date>2003/12/09</plugin_publication_date>
<plugin_type>combined</plugin_type>
<risk_factor>None</risk_factor>
<script_version>$Revision: 2.37 $</script_version>
<solution>n/a</solution>
<synopsis>It is possible to guess the remote operating system.</synopsis>

</ReportItem>
.....(Report Item repeats a with different findings)


The problem I have is that all the data is outputted per host address, but I need the data to be grouped by pluginID so instead of having "Host with these findings" I need "Findings with these hosts".

i.e.:

Current:

ReportHost/@name

Finding Attributes (Name, Description, etc)

Affected Port

Affected Port

Affected Port

Finding Attributes (Name, Description, etc)

Affected Port


ReportHost/@name

Finding Attributes (Name, Description, etc)

Affected Port

Affected Port

.

.

.


Required:

Finding Attributes (Name, Description, etc)

ReportHost/@name

Affected Port

Affected Port

Affected Port

ReportHost/@name

Affected Port


Finding Attributes (Name, Description, etc)

ReportHost/@name

Affected Port

Affected Port

.

.


I know I said I need it in excel, and I have already made a workable XSL for excel I'm just using HTML for the convenience of testing (no tools just notepad++ and Firefox). Sorry if I didn't explain very well. I think I need to use Muenchian Grouping as for-each-group is not permitted in excel, but I'm a XML noob and I cant seem to get my head around it.


Thanks in advance.


James



asked 1 min ago







XSL: Group parent attributes using matching child attribute

Aucun commentaire:

Enregistrer un commentaire