我很想删除每个不包含特定值的父级,例如
<drawableDictionary>l_njdocklod12</drawableDictionary>
下面使用的 XML 示例:
<?xml version="1.0" encoding="UTF-8"?>
<CMapTypes name="lodetnjdock_wh1">
<extensions />
<archetypes>
<Item type="CBaseArchetypeDef">
<lodDist value="550" />
<flags value="0" />
<specialAttribute value="0" />
<bbMin x="-12.3383" y="-6.42445" z="-13.3852" />
<bbMax x="12.3382" y="6.42445" z="13.3852" />
<bsCentre x="-5.05447E-05" y="2.38419E-06" z="0" />
<bsRadius value="19.3046" />
<hdTextureDist value="0" />
<name>hash_349C91C8</name>
<textureDictionary>njdocklod04</textureDictionary>
<clipDictionary />
<drawableDictionary>lodnjdocksuper11_grp</drawableDictionary>
<physicsDictionary>nj_docks</physicsDictionary>
<assetType>ASSET_TYPE_DRAWABLEDICTIONARY</assetType>
<assetName>hash_349C91C8</assetName>
<extensions />
</Item>
<Item type="CBaseArchetypeDef">
<lodDist value="550" />
<flags value="0" />
<specialAttribute value="0" />
<bbMin x="-5.6393" y="-5.45088" z="-4.9861" />
<bbMax x="5.6393" y="5.45088" z="4.9861" />
<bsCentre x="0" y="-4.76837E-07" z="4.76837E-07" />
<bsRadius value="9.29382" />
<hdTextureDist value="0" />
<name>hash_46EE366B</name>
<textureDictionary>njdocklod12</textureDictionary>
<clipDictionary />
<drawableDictionary>l_njdocklod12</drawableDictionary>
<physicsDictionary>nj_docks</physicsDictionary>
<assetType>ASSET_TYPE_DRAWABLEDICTIONARY</assetType>
<assetName>hash_46EE366B</assetName>
<extensions />
</Item>
<Item type="CBaseArchetypeDef">
<lodDist value="550" />
<flags value="0" />
<specialAttribute value="0" />
<bbMin x="-11.8993" y="-34.8797" z="-4.27972" />
<bbMax x="11.8992" y="34.8796" z="4.29434" />
<bsCentre x="-2.76566E-05" y="-1.52588E-05" z="0.0073123" />
<bsRadius value="37.102" />
<hdTextureDist value="0" />
<name>hash_52EAB9C8</name>
<textureDictionary>njdocklod10</textureDictionary>
<clipDictionary />
<drawableDictionary>lodnjdocksuper05_grp</drawableDictionary>
<physicsDictionary>nj_docks</physicsDictionary>
<assetType>ASSET_TYPE_DRAWABLEDICTIONARY</assetType>
<assetName>hash_52EAB9C8</assetName>
<extensions />
</Item>
</archetypes>
<name>nj_docks_lod</name>
<dependencies />
<compositeEntityTypes itemType="CCompositeEntityType" />
</CMapTypes>
想要的结果
<?xml version="1.0" encoding="UTF-8"?>
<CMapTypes name="lodetnjdock_wh1">
<extensions />
<archetypes>
<Item type="CBaseArchetypeDef">
<lodDist value="550" />
<flags value="0" />
<specialAttribute value="0" />
<bbMin x="-5.6393" y="-5.45088" z="-4.9861" />
<bbMax x="5.6393" y="5.45088" z="4.9861" />
<bsCentre x="0" y="-4.76837E-07" z="4.76837E-07" />
<bsRadius value="9.29382" />
<hdTextureDist value="0" />
<name>hash_46EE366B</name>
<textureDictionary>njdocklod12</textureDictionary>
<clipDictionary />
<drawableDictionary>l_njdocklod12</drawableDictionary>
<physicsDictionary>nj_docks</physicsDictionary>
<assetType>ASSET_TYPE_DRAWABLEDICTIONARY</assetType>
<assetName>hash_46EE366B</assetName>
<extensions />
</Item>
</archetypes>
<name>nj_docks_lod</name>
<dependencies />
<compositeEntityTypes itemType="CCompositeEntityType" />
</CMapTypes>
我想使用正则表达式使用Notepad++来实现这一点,因为我离我的舒适区很远,到目前为止这对我有用。
这项工作的工具是 XSLT。这是一个非常简单的转换:复制所有内容不变的身份模板加上删除不需要的项目的规则:
<xsl:template match="Item[not(drawableDictionary='l_njdocklod12')]"/>
在 XSLT 3.0 中,您可以通过编写来获取身份模板
<xsl:mode on-no-match="shallow-copy"/>
在旧版本中,写
<xsl:template match="@*|node()">
<xsl:copy><xsl:apply-templates select="@*|node()"/></xsl:copy>
</xsl:template>