从XML中删除元素

时间:2010-12-08 18:45:08

标签: xml transform

我有以下格式的XML:

<policy_groups>
    <policy_group>
    <policygroup_name>Application Server with IIS</policygroup_name>
        <policygroup_id>38</policygroup_id>
        <policygroup_description />
        <policygroup_creatorname>VMW2K3-SSI10-KF\VMW2K3-SSI10-KF\Administrator</policygroup_creatorname>
        <policygroup_patchgroup>-1</policygroup_patchgroup>
        <policygroup_signaturegroup>-1</policygroup_signaturegroup>
        <policygroup_system>false</policygroup_system>
        <policygroup_item>
            <policygroupitem_id>83217</policygroupitem_id>
            <policygroupitem_name>.NET Framework Support Service Status</policygroupitem_name>
            <policygroupitem_type>0</policygroupitem_type>
            <policygroupitem_policygroupid>38</policygroupitem_policygroupid>
            <policygroupitem_productname>Windows Server 2003, Standard Edition</policygroupitem_productname>
            <policygroupitem_spname>Gold</policygroupitem_spname>
            <policygroupitem_checkshavlikid>207</policygroupitem_checkshavlikid>
            <policygroupitem_value>Disabled-Not Found</policygroupitem_value>
            <policygroupitem_operator>=</policygroupitem_operator>
            <policygroupitem_displayvalue>Not Installed</policygroupitem_displayvalue>
        </policygroup_item>
        <policygroup_item>
            <policygroupitem_id>85541</policygroupitem_id>
            <policygroupitem_name>.NET Framework Support Service Status</policygroupitem_name>
            <policygroupitem_type>0</policygroupitem_type>
            <policygroupitem_policygroupid>38</policygroupitem_policygroupid>
            <policygroupitem_productname>Windows Server 2003, Standard Edition</policygroupitem_productname>
            <policygroupitem_spname>SP1</policygroupitem_spname>
            <policygroupitem_checkshavlikid>207</policygroupitem_checkshavlikid>
            <policygroupitem_value>Disabled-Not Found</policygroupitem_value>
            <policygroupitem_operator>=</policygroupitem_operator>
            <policygroupitem_displayvalue>Not Installed</policygroupitem_displayvalue>
        </policygroup_item>
    </policy_group>
    </policy_groups>

除了XML文档中有数千个<policygroup_item>之外。

我需要移除policygroup_item<policygroupitem_productname>与以下任意组合不匹配的任何<policygroupitem_spname>

  • Windows 2000 Advanced Server SP4
  • Windows 2003 Enterprise Edition SP2
  • Windows 2003企业版(x64)SP2
  • Windows 2003 R2企业版SP2
  • Windows 2003 R2企业版(x64)SP2
  • Windows 2008 Enterprise Edition SP2
  • Windows 2008企业版(x64)SP2
  • Windows 2008 Standard Edition SP2
  • Windows 2008 R2 Standard(x64)Gold
  • Windows 2008 R2 Enterprise(x64)Gold

有没有办法用XSLT或PowerShell做到这一点?或者也许是VB脚本?

由于

布拉德

1 个答案:

答案 0 :(得分:1)

不要将其视为删除不匹配的那些,将其视为复制匹配的那些。在选择要保留的所有标记上使用<xsl:copy-of> element