-1

リストに基づいて xml タグをフィルタリングしようとしています。

リストの例: ファイル名 list.txt

1
2
3
4
5
6

サンプル XML

< id=1 />
< id=4 />
< id=11 />
< id=3 />
< id=23 />

XPath を使用していますか? list.txtにないものだけを残すためにxmlタグをフィルタリングするxpathクエリを書くことは可能ですか?

出力
< id=11 />
< id=23 />

これは xpath ステートメントで可能ですか?

4

1 に答える 1

0

フィードバックと提案を提供してくれたすべての人に感謝します。私は自分の問題を理解しました。私のソリューションに関するフィードバックを提供して、改善できるかどうかを確認してください。ありがとう..

私の問題は Nessus に関係しています。その報道はひどい。.nessus ファイル ver2 をチェックアウトして、必要なタグの情報をまとめることができました。同様のレポートを使用できる他の Nessus ユーザーのためにここに掲載します。

重要でないプラグイン情報をレポートから除外する方法が必要でした。最適な方法は、xml ファイルをスプレッドシート アプリの便利な表形式にフォーマットするために使用していた xslt を使用してプラグインをフィルター処理することであると判断しました。不要な Nessus プラグインを含むタグを格納するために別の xml ファイルを使用することにしました。xml ファイルの構造は次のようになりました。

<?xml version="1.0" encoding="ISO-8859-1"?>
<exclude>
  <nessusPlugin>19506</nessusPlugin>
  <nessusPlugin>45590</nessusPlugin>
</exclude>

「ドキュメント」機能を調べるという提案に従い、最終的に次の 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 &lt; 2) Count: <xsl:value-of select="count(NessusClientData_v2/Report/ReportHost/ReportItem[@severity&lt;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>

私はこれを一緒にハックして、これらの解決策を思いつきました: 1.不要なプラグイン リストを含む xml ファイルを追加するには:

<xsl:variable name="excludedplugins" select="document('nessusExcludePluginList.xml')/exclude/nessusPlugin"/>
  1. 除外されたプラグインと比較するには:

私が試してみるまで、比較についてはよくわかりませんでした。これは、ノード内のすべてのアイテムで機能することがわかりました。なんとお得!私が理解していないのは、これが機能しない理由です:

<xsl:when test="@pluginID!=$excludedplugins">

= 演算子はすべてのノードをチェックしますが、!= はまったく機能していないようです。「not」機能が存在するのは良いことです。

これを改善するために私がやりたいことは、次のように、xml ファイルの代わりにプラグイン番号のストレート リストを使用して不要なプラグインのリストをフィードする方法があるかどうかを確認することです: 58181 34252 34220 11219 10335 22964

また、「for each」を使用しない、よりエレガントなソリューションがあると思います。とにかく、みんな助けてくれてありがとう。

于 2012-04-19T15:07:12.110 に答える