开发者

Remove elements from XML

I have XML in the following format:

<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>

Except there are thousands of <policygroup_item>'s in the XML document.

I need to remove any policygroup_item where <policygroupitem_productname> and <policygroupitem_spname> don't match any of the following combinations:

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

Is there some way to do this with XSLT or powershell? Or maybe VB script?

Thanks

Brad


Don't think of it as removing the ones that don't match, think of it as copying the ones that do match. Use the <xsl:copy-of> element on a selection of all the tags you want to keep.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜