【发布时间】:2015-01-30 08:37:12
【问题描述】:
大家好,我正在尝试使用转换 XML 文档将表格直接输出到 Excel 中。我遇到的问题是我需要按子节点对元素进行分组。我当前的 XSLT 是这样的:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="ScanData">
<html>
<body>
<xsl:for-each select="Report/ReportHost">
<xsl:if test="ReportItem/@severity > 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 > 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>
示例 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>
.....(ReportItem and ReportHost repeat with different findings and hosts)
我遇到的问题是,所有数据都是按主机地址输出的,但我需要按 pluginID 对数据进行分组,因此我需要“带有这些发现的主机”而不是“带有这些发现的主机”。
即:
当前:
ReportHost/@name
查找属性(名称、描述等)
受影响的端口
受影响的端口
受影响的端口
查找属性(名称、描述等)
受影响的端口 em>
ReportHost/@name
查找属性(名称、描述等)
受影响的端口
受影响的港口
.
.
.
必需:
查找属性(名称、描述等)
ReportHost/@name
受影响的端口
受影响的端口
受影响的端口
ReportHost/@name
受影响的端口
查找属性(名称、描述等)
ReportHost/@name
受影响的端口
受影响的港口
.
.
我知道我说过我需要在 excel 中使用它,并且我已经为 excel 制作了一个可行的 XSL 我只是使用 HTML 来方便测试(没有工具,只有 notepad++ 和 Firefox)。对不起,如果我没有很好地解释。我想我需要使用 Muenchian 分组,因为 excel 中不允许使用每个组,但我是 XML 新手,我似乎无法理解它。
提前致谢。
詹姆斯
【问题讨论】:
-
是否可以修改您的问题以显示稍大的 XML 示例。一个显示属于不同主机/插件的
ReportItem元素!不过,您可以通过删除ReportItem元素中的一些字段来减小大小。此外,显示该样本的预期实际输出可能是一个好主意。谢谢!