1
在下面的文件中,如果屬性UMProductId的值爲「放射療法」,我想刪除/刪除CPT元素。刪除父元素如果子元素不存在元素
<?xml version="1.0" encoding="us-ascii"?>
<AuthBatch SchemaVersion="1.0" InsurerId="123" Sequence="110" CreateDate="2014-07-10T02:45:02.317" AuthorizationCount="3">
<Authorizations>
<Authorization EffectiveDate="2014-07-09" Id="12345">
<CPTs>
<CPT Sequence="1" UMProductId="Radiation Therapy" ChangeStatus="ADD" ResendIndicator="INITIAL" />
<CPT Sequence="2" UMProductId="Radiation Therapy" ChangeStatus="ADD" ResendIndicator="INITIAL" />
<CPT Sequence="3" UMProductId="Radiation Therapy" ChangeStatus="ADD" ResendIndicator="INITIAL" />
</CPTs>
<Program Id="46756" Name="test" ChangeStatus="ADD" />
</Authorization>
<Authorization EffectiveDate="2014-07-09" Id="12345">
<CPTs>
<CPT Sequence="1" UMProductId="test" ChangeStatus="ADD" ResendIndicator="INITIAL" />
<CPT Sequence="2" UMProductId="Radiation Therapy" ChangeStatus="ADD" ResendIndicator="INITIAL" />
<CPT Sequence="3" UMProductId="Radiation Therapy" ChangeStatus="ADD" ResendIndicator="INITIAL" />
</CPTs>
<Program Id="46756" Name="test" ChangeStatus="ADD" />
</Authorization>
</Authorizations>
</AuthBatch>
但是,在一個授權,如果所有的CPT/UMProductId值是「放射治療」的話,我想刪除整個授權本身。
下面是我的XSLT,這是消除CPT元素,但不是授權:
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0" >
<xsl:template match="@* | node()">
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="AuthBatch/Authorizations/Authorization/CPTs/CPT[@UMProductId='RADIATION THERAPY' or
@UMProductId='Radiation Therapy']"/>
<xsl:template match="AuthBatch/Authorizations/Authorization[not(CPTs/CPT)]"/>
</xsl:stylesheet>
MyOutput中:
<?xml version="1.0" encoding="UTF-8"?>
<?xml version="1.0" encoding="us-ascii"?>
<AuthBatch SchemaVersion="1.0" InsurerId="123" Sequence="110" CreateDate="2014-07-10T02:45:02.317" AuthorizationCount="3">
<Authorizations>
<Authorization EffectiveDate="2014-07-09" Id="12345">
<CPTs/>
<Program Id="46756" Name="test" ChangeStatus="ADD" />
</Authorization>
<Authorization EffectiveDate="2014-07-09" Id="4567">
<CPTs>
<CPT Sequence="1" UMProductId="test" ChangeStatus="ADD" ResendIndicator="INITIAL" />
</CPTs>
<Program Id="46756" Name="test" ChangeStatus="ADD" />
</Authorization>
</Authorizations>
</AuthBatch>
預期輸出:
<?xml version="1.0" encoding="UTF-8"?>
<?xml version="1.0" encoding="us-ascii"?>
<AuthBatch SchemaVersion="1.0" InsurerId="123" Sequence="110" CreateDate="2014-07-10T02:45:02.317" AuthorizationCount="3">
<Authorizations>
<Authorization EffectiveDate="2014-07-09" Id="4567">
<CPTs>
<CPT Sequence="1" UMProductId="test" ChangeStatus="ADD" ResendIndicator="INITIAL" />
</CPTs>
<Program Id="46756" Name="test" ChangeStatus="ADD" />
</Authorization>
</Authorizations>
</AuthBatch>
請幫助我。提前致謝!!。
感謝, 阿賈伊
非常感謝你michael.hor257k ...該代碼工作得很好:) – 2014-10-01 10:42:08