XML xpath?基于不在列表中的属性筛选xml标记
尝试根据列表筛选xml标记 列表示例:filename List.txt 1XML xpath?基于不在列表中的属性筛选xml标记,xml,xpath,Xml,Xpath,尝试根据列表筛选xml标记 列表示例:filename List.txt 1 2 3 4 5 6 示例XML 使用XPath?是否可以编写一个xpath查询来过滤xml标记,从而只保留list.txt中没有的内容 输出 这在xpath语句中可能吗?感谢所有提供反馈和建议的人。我已经解决了自己的问题。请提供我的解决方案的反馈,看看是否可以改进。谢谢 我的问题与我们有关。它的报告是可怕的。我能够查看.nessus文件,版本2,并将我需要的标签中的信息拼凑在一起。我将把它放在这里,供其他
2
3
4
5
6
示例XML
使用XPath?是否可以编写一个xpath查询来过滤xml标记,从而只保留list.txt中没有的内容 输出
这在xpath语句中可能吗?感谢所有提供反馈和建议的人。我已经解决了自己的问题。请提供我的解决方案的反馈,看看是否可以改进。谢谢 我的问题与我们有关。它的报告是可怕的。我能够查看.nessus文件,版本2,并将我需要的标签中的信息拼凑在一起。我将把它放在这里,供其他Nessus用户使用,他们可以使用类似的报告 我需要一种方法从报告中过滤出不重要的插件信息。我决定最好的方法是使用xslt过滤插件,我也使用xslt将xml文件格式化为电子表格应用程序的有用表格格式。我决定使用一个单独的xml文件来存储包含不需要的Nessus插件的标记。xml文件的结构如下所示:
<?xml version="1.0" encoding="ISO-8859-1"?>
<exclude>
<nessusPlugin>19506</nessusPlugin>
<nessusPlugin>45590</nessusPlugin>
</exclude>
19506
45590
我按照关于研究“document”函数的建议,最终提出了以下xslt:
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:variable name="excludedplugins" select="document('nessusExcludePluginList.xml')/exclude/nessusPlugin"/>
<xsl:template match="/">
<html>
<body>
<h2>
Nessus Report, Targets: <xsl:value-of select="count(NessusClientData_v2/Report/ReportHost)"/>
</h2>
<br/>High Risk Count: <xsl:value-of select="count(NessusClientData_v2/Report/ReportHost/ReportItem[risk_factor='High'])"/>
<br/>Medium Risk Count: <xsl:value-of select="count(NessusClientData_v2/Report/ReportHost/ReportItem[risk_factor='Medium'])"/>
<br/>Low Risk Count: <xsl:value-of select="count(NessusClientData_v2/Report/ReportHost/ReportItem[risk_factor='Low'])"/>
<br/>Irrelavant Risk (Severity < 2) Count: <xsl:value-of select="count(NessusClientData_v2/Report/ReportHost/ReportItem[@severity<2])"/>
<table border="1">
<tr bgcolor="#9acd32">
<th>DNS Name</th>
<th>NetBios Name</th>
<th>IP Address</th>
<th>MAC Address</th>
<th>Operating System</th>
<th>Port</th>
<th>Protocol</th>
<th>Service Name</th>
<th>n Plugin ID</th>
<th>n Severity</th>
<th>n Risk_Factor</th>
<th>n Plugin Name</th>
<th>n Plugin Family</th>
<th>Description</th>
<th>Plugin Output</th>
<th>Synopsis</th>
</tr>
<xsl:for-each select="NessusClientData_v2/Report/ReportHost">
<xsl:for-each select="ReportItem">
<xsl:choose>
<xsl:when test="not(@pluginID=$excludedplugins)">
<tr>
<td><xsl:value-of select="../@name"/></td>
<td><xsl:value-of select="../HostProperties/tag[@name='netbios-name']"/></td>
<td><xsl:value-of select="../HostProperties/tag[@name='host-ip']"/></td>
<td><xsl:value-of select="../HostProperties/tag[@name='mac-address']"/></td>
<td><xsl:value-of select="../HostProperties/tag[@name='operating-system']"/></td>
<td><xsl:value-of select="@port"/></td>
<td><xsl:value-of select="@protocol"/></td>
<td><xsl:value-of select="@svc_name"/></td>
<td><xsl:value-of select="@pluginID"/></td>
<td><xsl:value-of select="@severity"/></td>
<td><xsl:value-of select="risk_factor"/></td>
<td><xsl:value-of select="@pluginName"/></td>
<td><xsl:value-of select="@pluginFamily"/></td>
<td><xsl:value-of select="description"/></td>
<td><xsl:value-of select="plugin_output"/></td>
<td><xsl:value-of select="synopsis"/></td>
</tr>
</xsl:when>
<xsl:otherwise>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
Nessus报告,目标:
高风险计数:
中等风险计数:
低风险计数:
不相关风险(严重程度2)计数:
DNS名称
NetBios名称
IP地址
MAC地址
操作系统
港口
协议
服务名称
插件ID
严重性
n风险系数
插件名
n插件族
描述
插件输出
提要
我将其整合在一起,并提出了以下解决方案:
1.要添加包含不需要的插件列表的xml文件,请执行以下操作:
<xsl:variable name="excludedplugins" select="document('nessusExcludePluginList.xml')/exclude/nessusPlugin"/>
<xsl:when test="@pluginID!=$excludedplugins">
=运算符将检查除!=之外的所有节点似乎根本不起作用。幸好“not”函数存在
我想做的是,看看是否有办法将不需要的插件列表直接输入插件编号列表,而不是xml文件,如下所示:
58181
34252
34220
11219
10335
22964
我还认为可能有一个更优雅的解决方案,不使用“for each”。无论如何,谢谢大家的帮助 我们需要了解XML的真实结构,因为您无法在xpath或xquery中读取文本文件。如果将文本文件转换为xml,可以使用fn:doc()函数加载新xml,然后按顺序获取值,并使用fn:exist(fn:index of(sequence,value))测试值是否在序列中。检查此链接中的xpath函数:您提供的“XML”和所需输出完全不是格式良好的XML。请说对。