XSLT一次忽略单个节点中的重复元素

XSLT一次忽略单个节点中的重复元素,xslt,Xslt,我想我之前的问题不清楚,所以我再次描述了情况 谢谢你在这方面的帮助。我试过了,但没能解决我的问题。我想我需要对我的问题提供更多的见解 <TXLife> <TXLifeResponse> <Coverage> <LifeParticipant id="Party_040_01"> <ParticipantName>Sam

我想我之前的问题不清楚,所以我再次描述了情况

谢谢你在这方面的帮助。我试过了,但没能解决我的问题。我想我需要对我的问题提供更多的见解

    <TXLife>
        <TXLifeResponse>
            <Coverage>
                <LifeParticipant id="Party_040_01">
                    <ParticipantName>Sam</ParticipantName>
                    <LifeParticipantRoleCode tc="1">Primary Insured</LifeParticipantRoleCode>
                    <RateDecision>Rating C 100%</RateDecision>
                </LifeParticipant>
            </Coverage>
            <Coverage>
                <LifeParticipant id="Party_040_02">
                    <ParticipantName>Renny</ParticipantName>
                    <LifeParticipantRoleCode tc="2">Additional Insured</LifeParticipantRoleCode>
                    <RateDecision>Rating B 200%</RateDecision>
                </LifeParticipant>
            </Coverage>
            <Coverage>
                <LifeParticipant id="Party_040_01">
                    <ParticipantName>Sam</ParticipantName>
                    <LifeParticipantRoleCode tc="1">Primary Insured</LifeParticipantRoleCode>
                    <RateDecision>Rating D 700%</RateDecision>
                </LifeParticipant>
            </Coverage>
        </TXLifeResponse>
        <TXLifeResponse>
            <Coverage>
                <LifeParticipant id="Party_040_01">
                    <ParticipantName>Marry</ParticipantName>
                    <LifeParticipantRoleCode tc="1">Primary Insured</LifeParticipantRoleCode>
                    <RateDecision>Rating C 100%</RateDecision>
                </LifeParticipant>
            </Coverage>
            <Coverage>
                <LifeParticipant id="Party_040_03">
                    <ParticipantName>Sherry</ParticipantName>
                    <LifeParticipantRoleCode tc="2">Primary Insured</LifeParticipantRoleCode>
                    <RateDecision>Rating H 300%</RateDecision>
                </LifeParticipant>
            </Coverage>
            <Coverage>
                <LifeParticipant id="Party_040_01">
                    <ParticipantName>Marry</ParticipantName>
                    <LifeParticipantRoleCode tc="1">Primary Insured</LifeParticipantRoleCode>
                    <RateDecision>Rating A 50%</RateDecision>
                </LifeParticipant>
            </Coverage>
        </TXLifeResponse>
    </TXLife>

山姆
主要被保险人
评级C 100%
雷尼
附加被保险人
评级B 200%
山姆
主要被保险人
评级D 700%
结婚
主要被保险人
评级C 100%
雪莉
主要被保险人
评级H 300%
结婚
主要被保险人
评级为50%
我需要通过LifeParticipationControleCode一次从TXLiferResponse中的多个覆盖范围元素中查找费率决策信息。对第二个TXLIFER响应重复相同的步骤,以此类推

    Meaning I need to generate output like

    <TXLife>
        <TXLifeResponse>
            <RateDecision>Sam Rating C 100%, Rating D 700%</RateDecision>
            <RateDecision>Renny Rating B 200%</RateDecision>
        </TXLifeResponse>
        <TXLifeResponse>
            <RateDecision>Marry Rating C 100%, Rating A 50%</RateDecision>
            <RateDecision>Sherry Rating H 300%</RateDecision>
        </TXLifeResponse>
    </TXLife>
意味着我需要生成如下输出
Sam等级C 100%,等级D 700%
雷尼评级B 200%
婚姻评级C 100%,评级A 50%
雪利酒等级H 300%
我不想为Sam生成两个元素。我想将Sam的评级信息从单个TXLiferResponse节点下的两个不同覆盖率元素组合起来,并显示它,然后对第二个TXLiferResponse节点重复相同的过程

我希望我能够澄清我的问题。感谢您的帮助

我试图实现下面的逻辑,但它仍然不起作用。请帮忙

<xsl:key name="LifeParticipant-by-LifeParticipantRoleCode" match="LifeParticipant" use="LifeParticipantRoleCode[@tc = '1' or @tc = '2' or @tc = '3' or @tc = '4' or @tc = '5' or @tc = '6']" />

<xsl:apply-templates select="Life/Coverage/LifeParticipant[generate-id() = generate-id(key('LifeParticipant-by-LifeParticipantRoleCode', LifeParticipantRoleCode/@tc)[1])]" />

<xsl:template match="LifeParticipant">
    <!-- Business Logic -->
</xsl:template>

我没有一个环境可以测试这一点,所以只有sudo代码,而且不能100%确定它会工作,但我会尝试解决这样的问题

Template Match at TXLifeResponse level
   for each coverage/LifeParticipant
     xsl:if test="not(preceding-sibling::LifeParticipant[@id=current()/@id])
       set variable (paramContext) to be current()    
       xslt:value-of setting value using a call to custom function (func1) passing paramContext, @id  and an empty string 
     end if
   end loop
end template
然后函数将使用递归,如下所示

 if test="(paramContext/following-sibling::LifeParticipant[@id=paramID])
    set variable newContext = paramContext/following-sibling::LifeParticipant[@id=paramID]
    set variable concatstring = paramString concatenated with delimiter and RateDecision
    call func1 (recursivly) passing NewContext, paramID, concatString
  end if
end loop
不确定上下文内容是否有效,但需要在此处执行某些操作,否则函数将更改外部部分的上下文。

删除重复项(在XSLT 1.0中)最好通过一种称为的技术来处理

这里需要的变化是在密钥中包含父节点的id。下面是一个实施示例:

XSLT1.0

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

<xsl:key name="k" match="Coverage" use="concat(LifeParticipant/@id, '|', generate-id(..))"/>

<xsl:template match="/TXLife">
    <root>
        <xsl:apply-templates select="TXLifeResponse"/>
    </root>
</xsl:template>

<xsl:template match="TXLifeResponse">
    <group>
        <xsl:apply-templates select="Coverage[count(. | key('k', concat(LifeParticipant/@id, '|', generate-id(..)))[1]) = 1]"/>
    </group>
</xsl:template>

<xsl:template match="Coverage">
    <item>
        <xsl:value-of select="LifeParticipant"/>
    </item>
</xsl:template>

</xsl:stylesheet>

应用于给定的示例输入,结果将为:

<?xml version="1.0" encoding="UTF-8"?>
<root>
   <group>
      <item>tom</item>
      <item>sam</item>
   </group>
   <group>
      <item>tom</item>
      <item>jerry</item>
   </group>
</root>

汤姆
山姆
汤姆
杰瑞

我在这里没有看到任何与“多个文件”有关的内容。

您想要的结果是什么,什么不起作用?上面的XSLT忽略了TXLiferResponse节点上重复的LifeParticipant/@id。我希望它仅在当前TxliferResponse节点内忽略LifeParticipant/@id,并将其应用于第二个TxliferResponse节点,以此类推。“我尝试了此操作,但无法解决我的问题。”发布您的尝试。-注意,不要用“紧急”这个词。这里的每个人都贡献了他们的时间,你没有权利催任何人。我道歉。我不想催任何人帮我。只是在这里呆了几天,没有任何突破。我已经从我的问题中去掉了“紧急”这个词。谢谢你在这方面的帮助,但我无法用这个来解决我的问题。我已经更新了我的原始问题,以便更深入地了解我的问题领域。请回顾我的原始问题并提供您的帮助。我的答案是正确的。原则是一样的,区别是微小的。请自行调整。很抱歉更新得太晚。我能够使用您的解决方案(Muenchian分组)解决问题。感谢您的帮助。嗨,肖恩,我试过这个,但它似乎不起作用。@user2324686更新了答案以符合您修改/澄清的要求。