如何根据输入条件输出

时间:2014-12-31 06:13:54

标签: xml xslt xslt-1.0

1)如果在2个不同的策略上有多个具有CategoryCd = GL AND selectedInd ='Y'并且deletedInd ='Y'的实例,则使用返回码FAILURE失败并返回原因代码MANYPOL

<policy VERSION_NO="1" MC_ID="66" ID="1">
    <businessGroupCdGvngOrgn>14</businessGroupCdGvngOrgn>
            <linesOfInsurance>
                <underlyingPolicy>
                    <PolicyNo>22</PolicyNo>
                    <deletedInd>Y</deletedInd>
                    <VersionNbr>2</VersionNbr>
                    <selectedInd>Y</selectedInd>
                    <CategoryCd>GL</CategoryCd>
                </underlyingPolicy>
                <underlyingPolicy ID="5">
                    <PolicyNo>22</PolicyNo>
                    <deletedInd>Y</deletedInd>
                    <VersionNbr>1</VersionNbr>
                    <selectedInd>N</selectedInd>
                    <CategoryCd>GL</CategoryCd>
                </underlyingPolicy>     
                <underlyingPolicy ID="4">
                    <PolicyNo>11</PolicyNo>
                    <deletedInd>N</deletedInd>
                    <VersionNbr>2</VersionNbr>
                    <selectedInd>Y</selectedInd>
                    <CategoryCd>GL</CategoryCd>
                </underlyingPolicy>
                <underlyingPolicy ID="3">
                    <PolicyNo>11</PolicyNo>
                    <deletedInd>Y</deletedInd>
                    <VersionNbr>1</VersionNbr>
                    <selectedInd>Y</selectedInd>
                    <CategoryCd>GL</CategoryCd>
                </underlyingPolicy>     
            </linesOfInsurance>
        </policy>
Expected O/P:
<AdaptikXML>
    <PWResponse>
        <ReturnCode>FAILURE</ReturnCode>
        <ReturnReasonCode>MANYPOL</ReturnReasonCode>
        <PWData>
            <policy VERSION_NO="1" MC_ID="66"/>
        </PWData>
    </PWResponse>
</AdaptikXML>
--------------------------------------------------------------------------------

2)如果同一策略中有多个具有underlyingPolicyCategoryCd = GL AND selectedInd ='Y'并且deletedInd ='Y'的实例,则FAIL返回代码为FAILURE并返回原因代码MANY

<policy VERSION_NO="1" MC_ID="34">
    <businessGroupCd>14</businessGroupCd>
            <linesOfInsurance>
                <underlyingPolicy>
                    <PolicyNo>22</PolicyNo>
                    <deletedInd>Y</deletedInd>
                    <VersionNbr>2</VersionNbr>
                    <selectedInd>N</selectedInd>
                    <CategoryCd>GL</CategoryCd>
                </underlyingPolicy>
                <underlyingPolicy ID="5">
                    <PolicyNo>22</PolicyNo>
                    <deletedInd>Y</deletedInd>
                    <VersionNbr>1</VersionNbr>
                    <selectedInd>N</selectedInd>
                    <CategoryCd>GL</CategoryCd>
                </underlyingPolicy>     
                <underlyingPolicy ID="4">
                    <PolicyNo>11</PolicyNo>
                    <deletedInd>Y</deletedInd>
                    <VersionNbr>2</VersionNbr>
                    <selectedInd>Y</selectedInd>
                    <CategoryCd>GL</CategoryCd>
                </underlyingPolicy>
                <underlyingPolicy ID="3">
                    <PolicyNo>11</PolicyNo>
                    <deletedInd>Y</deletedInd>
                    <VersionNbr>1</VersionNbr>
                    <selectedInd>Y</selectedInd>
                    <CategoryCd>GL</CategoryCd>
                </underlyingPolicy>     
            </linesOfInsurance>
        </policy>
Expected O/P:
<AdaptikXML>
        <PWResponse>
            <ReturnCode>FAILURE</ReturnCode>
            <ReturnReasonCode>MANY</ReturnReasonCode>
            <PWData>
                <policy VERSION_NO="1" MC_ID="34"/>
            </PWData>
        </PWResponse>    
</AdaptikXML>
--------------------------------------------------------------------------------

3)如果MANYPOL和MANY条件都为真,则应返回MANYPOL(这意味着您可以先检查MANYPOL条件,如果是,则可以停止处理并返回

<policy VERSION_NO="1" MC_ID="66">
    <businessGroupCdGvngOrgn>14</businessGroupCdGvngOrgn>
            <linesOfInsurance>
                <underlyingPolicy>
                    <PolicyNo>22</PolicyNo>
                    <deletedInd>Y</deletedInd>
                    <VersionNbr>2</VersionNbr>
                    <selectedInd>Y</selectedInd>
                    <CategoryCd>GL</CategoryCd>
                </underlyingPolicy>
                <underlyingPolicy ID="5">
                    <PolicyNo>22</PolicyNo>
                    <deletedInd>Y</deletedInd>
                    <VersionNbr>1</VersionNbr>
                    <selectedInd>N</selectedInd>
                    <CategoryCd>GL</CategoryCd>
                </underlyingPolicy>     
                <underlyingPolicy ID="4">
                    <PolicyNo>11</PolicyNo>
                    <deletedInd>Y</deletedInd>
                    <VersionNbr>2</VersionNbr>
                    <selectedInd>Y</selectedInd>
                    <CategoryCd>GL</CategoryCd>
                </underlyingPolicy>
                <underlyingPolicy ID="3">
                    <PolicyNo>11</PolicyNo>
                    <deletedInd>Y</deletedInd>
                    <VersionNbr>1</VersionNbr>
                    <selectedInd>Y</selectedInd>
                    <CategoryCd>GL</CategoryCd>
                </underlyingPolicy>     
            </linesOfInsurance>
        </policy>
EXPECTED O/P:
    <AdaptikXML>
        <PWResponse>
            <ReturnCode>FAILURE</ReturnCode>
            <ReturnReasonCode>MANYPOL</ReturnReasonCode>
            <PWData>
                <policy VERSION_NO="1" MC_ID="66"/>
            </PWData>
        </PWResponse>
</AdaptikXML>

4)如果没有具有underlyingPolicyCategoryCd = GL且且selectedInd ='Y'并且deletedInd ='Y'的实例,则返回代码= SUCCESS并返回原因代码NOCHANGE

<policy VERSION_NO="1" MC_ID="56">
      <businessGroupCdGvngOrgn>14</businessGroupCdGvngOrgn>
        <linesOfInsurance>
            <underlyingPolicy ID="8">
                <PolicyNo>33</PolicyNo>
                <deletedInd>N</deletedInd>
                <VersionNbr>2</VersionNbr>
                <selectedInd>Y</selectedInd>
                <CategoryCd>AL</CategoryCd>
            </underlyingPolicy>
            <underlyingPolicy ID="7">
                <PolicyNo>33</PolicyNo>
                <deletedInd>Y</deletedInd>
                <VersionNbr>1</VersionNbr>
                <selectedInd>N</selectedInd>
                <CategoryCd>AL</CategoryCd>
            </underlyingPolicy>         
            <underlyingPolicy>
                <PolicyNo>22</PolicyNo>
                <deletedInd>Y</deletedInd>
                <VersionNbr>2</VersionNbr>
                <selectedInd>N</selectedInd>
                <CategoryCd>GL</CategoryCd>
            </underlyingPolicy>
            <underlyingPolicy ID="5">
                <PolicyNo>22</PolicyNo>
                <deletedInd>Y</deletedInd>
                <VersionNbr>1</VersionNbr>
                <selectedInd>N</selectedInd>
                <CategoryCd>GL</CategoryCd>
            </underlyingPolicy>     
            <underlyingPolicy ID="4">
                <PolicyNo>11</PolicyNo>
                <deletedInd>N</deletedInd>
                <VersionNbr>2</VersionNbr>
                <selectedInd>Y</selectedInd>
                <CategoryCd>GL</CategoryCd>
            </underlyingPolicy>
            <underlyingPolicy ID="3">
                <PolicyNo>11</PolicyNo>
                <deletedInd>Y</deletedInd>
                <VersionNbr>1</VersionNbr>
                <selectedInd>N</selectedInd>
                <CategoryCd>GL</CategoryCd>
            </underlyingPolicy>     
        </linesOfInsurance>
    </policy>
Expected O/P:
<AdaptikXML>
    <PWResponse>
        <ReturnCode>SUCCESS</ReturnCode>
        <ReturnReasonCode>NOCHANGE</ReturnReasonCode>
        <ReturnMessage/>
        <PWData>
            <policy VERSION_NO="1" MC_ID="56"/>
        </PWData>
    </PWResponse>
</AdaptikXML>

测试用例3 - 2个GL策略,每个策略有2个引用版本。策略22版本1选择了'='并且删除了'='并且策略11版本1已经选择了='Y'并且删除了'='N'。其他2个版本选择了'='N'并且删除了'='Y'。最终结果应该是策略22版本1已选择'='Y'并且已删除并且='N'且策略11版本1已选择并且='N'且已删除并且='Y'。

<policy VERSION_NO="1" MC_ID="66">
    <businessGroupCdGvngOrgn>14</businessGroupCdGvngOrgn>
    <linesOfInsurance>            <underlyingPolicy>
            <PolicyNo>22</PolicyNo>
            <deletedInd>Y</deletedInd>
            <VersionNbr>2</VersionNbr>
            <selectedInd>N</selectedInd>
            <CategoryCd>GL</CategoryCd>
        </underlyingPolicy>
        <underlyingPolicy ID="5">
            <PolicyNo>22</PolicyNo>
            <deletedInd>Y</deletedInd>
            <VersionNbr>1</VersionNbr>
            <selectedInd>Y</selectedInd>
            <CategoryCd>GL</CategoryCd>
        </underlyingPolicy>     
        <underlyingPolicy ID="4">
            <PolicyNo>11</PolicyNo>
            <deletedInd>Y</deletedInd>
            <VersionNbr>2</VersionNbr>
            <selectedInd>N</selectedInd>
            <CategoryCd>GL</CategoryCd>
        </underlyingPolicy>
        <underlyingPolicy ID="3">
            <PolicyNo>11</PolicyNo>
            <deletedInd>N</deletedInd>
            <VersionNbr>1</VersionNbr>
            <selectedInd>Y</selectedInd>
            <CategoryCd>GL</CategoryCd>
        </underlyingPolicy>     
    </linesOfInsurance>
</policy>

预期的O / P:

<AdaptikXML>
    <PWResponse>
        <ReturnCode>SUCCESS</ReturnCode>
        <ReturnReasonCode>CHANGE</ReturnReasonCode>
        <ReturnMessage/>
        <PWData>
            <policy VERSION_NO="1" MC_ID="66" ExtAction="U">
                <linesOfInsurance ExtAction="U">
                    <underlyingPolicy ID="5" ExtAction="U">
                        <PolicyNo>22</PolicyNo>
                        <VersionNbr>1</VersionNbr>
                        <selectedInd>Y</selectedInd>
                        <deletedInd>N</deletedInd>
                    </underlyingPolicy>
                    <underlyingPolicy ID="3" ExtAction="U">
                        <PolicyNo>11</PolicyNo>
                        <VersionNbr>1</VersionNbr>
                        <selectedInd>N</selectedInd>
                        <deletedInd>Y</deletedInd>
                    </underlyingPolicy>
                </linesOfInsurance>
            </policy>
        </PWData>
    </PWResponse>
</AdaptikXML>

-___________________________________________________________________________________________

测试用例4 - 2个AL策略,1个有2个引用版本,1个有3个。策略33版本1选择了'='Y'并且deletedInd ='Y'和策略44版本2已经选择了'='Y'并且已删除了='Y'。最终结果应为Policy 33版本1,Policy 44版本2为selectedInd ='Y'且deletedInd ='N'。策略33版本2和策略44版本1选择了'='N'并且已删除并且='Y'。策略44版本3保持不变(selectedInd ='N'和deletedInd ='Y')

    <policy VERSION_NO="1" MC_ID="55">        
<businessGroupCdGvngOrgn>14</businessGroupCdGvngOrgn>
        <linesOfInsurance>            
<underlyingPolicy ID="7">
                <PolicyNo>44</PolicyNo>
                <deletedInd>Y</deletedInd>
                <VersionNbr>3</VersionNbr>
                <selectedInd>N</selectedInd>
                <CategoryCd>AL</CategoryCd>
            </underlyingPolicy>     
            <underlyingPolicy>
                <PolicyNo>44</PolicyNo>
                <deletedInd>Y</deletedInd>
                <VersionNbr>2</VersionNbr>
                <selectedInd>Y</selectedInd>
                <CategoryCd>AL</CategoryCd>
            </underlyingPolicy>
            <underlyingPolicy ID="5">
                <PolicyNo>44</PolicyNo>
                <deletedInd>N</deletedInd>
                <VersionNbr>1</VersionNbr>
                <selectedInd>Y</selectedInd>
                <CategoryCd>AL</CategoryCd>
            </underlyingPolicy>     
            <underlyingPolicy ID="4">
                <PolicyNo>33</PolicyNo>
                <deletedInd>N</deletedInd>
                <VersionNbr>2</VersionNbr>
                <selectedInd>Y</selectedInd>
                <CategoryCd>AL</CategoryCd>
            </underlyingPolicy>
            <underlyingPolicy ID="3">
                <PolicyNo>33</PolicyNo>
                <deletedInd>Y</deletedInd>
                <VersionNbr>1</VersionNbr>
                <selectedInd>Y</selectedInd>
                <CategoryCd>AL</CategoryCd>
            </underlyingPolicy>     
        </linesOfInsurance>
    </policy>

预期o / p:

<AdaptikXML>
    <PWResponse>
        <ReturnCode>SUCCESS</ReturnCode>
        <ReturnReasonCode>CHANGE</ReturnReasonCode>
        <ReturnMessage/>
        <PWData>
            <policy VERSION_NO="1" MC_ID="55" ExtAction="U">
                <linesOfInsurance ExtAction="U">
                    <underlyingPolicy ExtAction="U">
                        <PolicyNo>44</PolicyNo>
                        <VersionNbr>2</VersionNbr>
                        <selectedInd>Y</selectedInd>
                        <deletedInd>N</deletedInd>
                    </underlyingPolicy>
                    <underlyingPolicy ID="5" ExtAction="U">
                        <PolicyNo>44</PolicyNo>
                        <VersionNbr>1</VersionNbr>
                        <selectedInd>N</selectedInd>
                        <deletedInd>Y</deletedInd>
                    </underlyingPolicy>
                    <underlyingPolicy ID="4" ExtAction="U">
                        <PolicyNo>33</PolicyNo>
                        <VersionNbr>2</VersionNbr>
                        <selectedInd>N</selectedInd>
                        <deletedInd>Y</deletedInd>
                    </underlyingPolicy>
                    <underlyingPolicy ID="3" ExtAction="U">
                        <PolicyNo>33</PolicyNo>
                        <VersionNbr>1</VersionNbr>
                        <selectedInd>Y</selectedInd>
                        <deletedInd>N</deletedInd>
                    </underlyingPolicy>                 
                </linesOfInsurance>
            </policy>
        </PWData>
    </PWResponse>
</AdaptikXML>

测试用例5 - 最终结果应该是策略22版本1已选择'='Y'并且已删除并且='N'且策略11版本1已选择等于='N'且已删除并且='Y'。策略33版本1和策略44版本2具有selectedInd ='Y'和deletedInd ='N'。策略33版本2和策略44版本1选择了'='N'并且已删除并且='Y'。

<policy VERSION_NO="1" MC_ID="89">
    <businessGroupCdGvngOrgn>14</businessGroupCdGvngOrgn>
    <linesOfInsurance>
        <underlyingPolicy ID="10">
            <PolicyNo>44</PolicyNo>
            <deletedInd>Y</deletedInd>
            <VersionNbr>2</VersionNbr>
            <selectedInd>Y</selectedInd>
            <CategoryCd>AL</CategoryCd>
        </underlyingPolicy>
        <underlyingPolicy ID="9">
            <PolicyNo>44</PolicyNo>
            <deletedInd>N</deletedInd>
            <VersionNbr>1</VersionNbr>
            <selectedInd>Y</selectedInd>
            <CategoryCd>AL</CategoryCd>
        </underlyingPolicy>     
        <underlyingPolicy ID="8">
            <PolicyNo>33</PolicyNo>
            <deletedInd>N</deletedInd>
            <VersionNbr>2</VersionNbr>
            <selectedInd>Y</selectedInd>
            <CategoryCd>AL</CategoryCd>
        </underlyingPolicy>
        <underlyingPolicy ID="7">
            <PolicyNo>33</PolicyNo>
            <deletedInd>Y</deletedInd>
            <VersionNbr>1</VersionNbr>
            <selectedInd>Y</selectedInd>
            <CategoryCd>AL</CategoryCd>
        </underlyingPolicy>
        <underlyingPolicy>
            <PolicyNo>22</PolicyNo>
            <deletedInd>Y</deletedInd>
            <VersionNbr>2</VersionNbr>
            <selectedInd>N</selectedInd>
            <CategoryCd>GL</CategoryCd>
        </underlyingPolicy>
        <underlyingPolicy ID="5">
            <PolicyNo>22</PolicyNo>
            <deletedInd>Y</deletedInd>
            <VersionNbr>1</VersionNbr>
            <selectedInd>Y</selectedInd>
            <CategoryCd>GL</CategoryCd>
        </underlyingPolicy>     
        <underlyingPolicy ID="4">
            <PolicyNo>11</PolicyNo>
            <deletedInd>Y</deletedInd>
            <VersionNbr>2</VersionNbr>
            <selectedInd>N</selectedInd>
            <CategoryCd>GL</CategoryCd>
        </underlyingPolicy>
        <underlyingPolicy ID="3">
            <PolicyNo>11</PolicyNo>
            <deletedInd>N</deletedInd>
            <VersionNbr>1</VersionNbr>
            <selectedInd>Y</selectedInd>
            <CategoryCd>GL</CategoryCd>
        </underlyingPolicy>                 
    </linesOfInsurance>
</policy>

预期的O / P:

<AdaptikXML>
    <PWResponse>
        <ReturnCode>SUCCESS</ReturnCode>
        <ReturnReasonCode>CHANGE</ReturnReasonCode>
        <ReturnMessage/>
        <PWData>
            <policy VERSION_NO="1" MC_ID="89" ExtAction="U">
                <linesOfInsurance ExtAction="U">
                    <underlyingPolicy ID="5" ExtAction="U">
                        <PolicyNo>22</PolicyNo>
                        <VersionNbr>1</VersionNbr>
                        <selectedInd>Y</selectedInd>
                        <deletedInd>N</deletedInd>
                    </underlyingPolicy>
                    <underlyingPolicy ID="3" ExtAction="U">
                        <PolicyNo>11</PolicyNo>
                        <VersionNbr>1</VersionNbr>
                        <selectedInd>N</selectedInd>
                        <deletedInd>Y</deletedInd>
                    </underlyingPolicy>
                    <underlyingPolicy ID="10" ExtAction="U">
                        <PolicyNo>44</PolicyNo>
                        <VersionNbr>2</VersionNbr>
                        <selectedInd>Y</selectedInd>
                        <deletedInd>N</deletedInd>
                    </underlyingPolicy>
                    <underlyingPolicy ID="9" ExtAction="U">
                        <PolicyNo>44</PolicyNo>
                        <VersionNbr>1</VersionNbr>
                        <selectedInd>N</selectedInd>
                        <deletedInd>Y</deletedInd>
                    </underlyingPolicy>
                    <underlyingPolicy ID="8" ExtAction="U">
                        <PolicyNo>33</PolicyNo>
                        <VersionNbr>2</VersionNbr>
                        <selectedInd>N</selectedInd>
                        <deletedInd>Y</deletedInd>
                    </underlyingPolicy>
                    <underlyingPolicy ID="7" ExtAction="U">
                        <PolicyNo>33</PolicyNo>
                        <VersionNbr>1</VersionNbr>
                        <selectedInd>Y</selectedInd>
                        <deletedInd>N</deletedInd>
                    </underlyingPolicy>                                 
            </policy>
        </PWData>
    </PWResponse>
</AdaptikXML>

1 个答案:

答案 0 :(得分:0)

你的样式表看起来不仅仅是检查&#34; MANYPOL&#34;和&#34;许多&#34;但我会专注于手头的任务......

考虑使用密钥通过相关指标查找underlyingPolicy元素

<xsl:key name="policy" 
         match="underlyingPolicy" 
         use="concat(CategoryCd, '|', selectedInd, '|', deletedInd)" />

然后,您可以测试是否存在两个具有相同指标的不同政策编号,如下所示:

<xsl:when test="linesOfInsurance/underlyingPolicy
                   [PolicyNo != key('policy', concat(CategoryCd, '|', selectedInd, '|', deletedInd))/PolicyNo]">

这会为您提供MANYPOL结果。

现在,您可能只想通过更改&#34;而不是等于&#34;来检查MANY。到&#34;等于&#34;

<xsl:when test="linesOfInsurance/underlyingPolicy
                   [PolicyNo = key('policy', concat(CategoryCd, '|', selectedInd, '|', deletedInd))/PolicyNo]">

这不会起作用,因为它会将当前underlyingPolicy元素与自身匹配!而是创建包含PolicyNo

的第二个密钥
<xsl:key name="policy_with_no" 
         match="underlyingPolicy" 
         use="concat(PolicyNo, '|', CategoryCd, '|', selectedInd, '|', deletedInd)" />

然后,您可以检查是否存在多个共享相同指标的相同编号的策略,如下所示:

 <xsl:when test="linesOfInsurance/underlyingPolicy
                    [key('policy_with_no', concat(PolicyNo, '|',CategoryCd, '|', selectedInd, '|', deletedInd))[2]]">

通过使用xsl:choose,首先评估第一个xsl:when,因此即使MANY也为真,也会始终输出MANYPOL。

试试这个XSLT

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0" >
    <xsl:output method="xml" indent="yes" />

    <xsl:key name="policy" match="underlyingPolicy" use="concat(CategoryCd, '|', selectedInd, '|', deletedInd)" />
    <xsl:key name="policy_with_no" match="underlyingPolicy" use="concat(PolicyNo, '|', CategoryCd, '|', selectedInd, '|', deletedInd)" />

    <xsl:template match="/policy">
        <PWResponse>
            <xsl:choose>
                <xsl:when test="linesOfInsurance/underlyingPolicy[PolicyNo != key('policy', concat(CategoryCd, '|', selectedInd, '|', deletedInd))/PolicyNo]">
                    <ReturnCode>FAILURE</ReturnCode>
                    <ReturnReasonCode>MANYPOL</ReturnReasonCode>
                </xsl:when>
                <xsl:when test="linesOfInsurance/underlyingPolicy[key('policy_with_no', concat(PolicyNo, '|',CategoryCd, '|', selectedInd, '|', deletedInd))[2]]">
                    <ReturnCode>FAILURE</ReturnCode>
                    <ReturnReasonCode>MANYPOL</ReturnReasonCode>
                </xsl:when>
                <xsl:otherwise>
                    <ReturnCode>SUCCESS</ReturnCode>
                    <ReturnReasonCode></ReturnReasonCode>
                </xsl:otherwise>
            </xsl:choose>
        </PWResponse>
    </xsl:template>
</xsl:stylesheet>