请帮我从xml.Condition中删除重复的节点以删除重复的节点是非常复杂的。
条件1:在policyKey节点下的每个策略节点中,我必须检查policyNbr和PolicyFormCode / code以及policyEffectiveDt和policyID 如果它们相同,则在所有策略节点中是相同的,我只保留具有sourceSystemCd / code =' SCBP'的策略节点。介绍它。
条件2:如果在上述条件中policyNbr和PolicyFormCode / code以及policyEffectiveDt和policyID中的任何一个具有不同的值,我需要显示所有策略节点。
条件3:在策略1和策略2中,policyNbr和policyFormCd应该相同,那么我们必须使用policyId来消除策略。如果不相等则显示两者。这可能吗 ?所有条件都应该在单个xsl中工作。
条件1: 输入xml:
<policies>
<!-- policy 1-->
<policy>
<policyKey>
<policyNbr>4567</policyNbr>
<policyEffectiveDt>2014-11-14</policyEffectiveDt>
<policyFormCd>
<code>669</code>
</policyFormCd>
</policyKey>
<transactionSplitTrans>
<sourceSystemCd>
<code>ARA</code>
</sourceSystemCd>
</transactionSplitTrans>
</policy>
<!-- policy 2-->
<policy>
<policyKey>
<policyNbr>4567</policyNbr>
<policyEffectiveDt>2014-11-14</policyEffectiveDt>
<policyID>54545</policyID>
<policyFormCd>
<code>669</code>
</policyFormCd>
</policyKey>
<transactionSplitTrans>
<sourceSystemCd>
<code>SCBP</code>
</sourceSystemCd>
</transactionSplitTrans>
</policy>
<!-- third -->
<policy>
<policyKey>
<policyNbr>1234</policyNbr>
<policyID>115774001</policyID>
<policyEffectiveDt>2014-11-14</policyEffectiveDt>
<policyFormCd>
<code>660</code>
</policyFormCd>
</policyKey>
<transactionSplitTrans>
<sourceSystemCd>
<code>ARAR</code>
</sourceSystemCd>
</transactionSplitTrans>
</policy>
<!-- fourth -->
<policy>
<policyKey>
<policyEffectiveDt>2014-11-14</policyEffectiveDt>
<policyFormCd>
<code>660</code>
</policyFormCd>
<policyID>115774001</policyID>
<policyNbr>1234</policyNbr>
</policyKey>
<transactionSplitTrans>
<sourceSystemCd>
<code>SCBP</code>
</sourceSystemCd>
</transactionSplitTrans>
</policy>
</policies>
联盟3的预期输出:
<policies>
<!-- policy 2-->
<policy>
<policyKey>
<policyNbr>4567</policyNbr>
<policyEffectiveDt>2014-11-14</policyEffectiveDt>
<policyID>54545</policyID>
<policyFormCd>
<code>669</code>
</policyFormCd>
</policyKey>
<transactionSplitTrans>
<sourceSystemCd>
<code>SCBP</code>
</sourceSystemCd>
</transactionSplitTrans>
</policy>
</policies>
条件1和条件2适用于belwo xslt。需要在相同的xsl中包含条件3。
答案 0 :(得分:0)
您可以使用键来&#34; group&#34;重复。它将是包含所有字段的连锁键
<xsl:key
name="policy"
match="policy"
use="concat(policyKey/policyNbr, '|',
policyKey/policyEffectiveDt, '|',
policyKey/policyFormCd/code, '|',
policyKey/policyID)" />
然后,您可以使用模板忽略这样的模板:
<xsl:template match="policy[count(
key('policy', concat(policyKey/policyNbr, '|',
policyKey/policyEffectiveDt, '|',
policyKey/policyFormCd/code, '|',
policyKey/policyID))) > 1
and transactionSplitTrans/sourceSystemCd/code != 'SCBP']" />
试试这个XSLT
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
<xsl:output method="xml" indent="yes" />
<xsl:key
name="policy"
match="policy"
use="concat(policyKey/policyNbr, '|',
policyKey/policyEffectiveDt, '|',
policyKey/policyFormCd/code, '|',
policyKey/policyID)" />
<xsl:template match="policy[count(key('policy', concat(policyKey/policyNbr, '|', policyKey/policyEffectiveDt, '|', policyKey/policyFormCd/code, '|', policyKey/policyID))) > 1 and transactionSplitTrans/sourceSystemCd/code != 'SCBP']" />
<xsl:template match="@*|node()" name="identity">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>