具有 3 个键的串联的 Meunchian 分组

发布于 2024-11-09 15:15:59 字数 5006 浏览 0 评论 0原文

我知道这可能很简单,但我通过查看类似的问题做了很多尝试来找到答案。具有 3 个键的 concat 的 meunchian 分组工作正常,但如果输入不需要分组怎么办?我在下面提供了示例 xsl。如果仅出现一次 CLM 节点,则运行转换时获得的输出不会创建 CLM 节点。提前致谢。

输入文件

<?xml version="1.0" encoding="utf-8"?>
<PRV ProviderId="100" PName="Giga health"
Provsuv="1563">
    <CLT ClientId="4444" ClientFName="John"
      ClientLastName="Pulaski" Phone="56462561">
        <CLM Claimid="1"  DateOfService="01/02/2011"
          EndOfService="05/05/2011" ServiceId="S1"
          WorkerName="WORK1" WorkerId="6446"
          Unit= '5' Amount= '5000'/>
        <CLM Claimid="2"  DateOfService="01/02/2011"
         EndOfService="05/05/2011" ServiceId="S1"
         WorkerName="WORK1" WorkerId="6446"
         Unit= '6' Amount= '5000'/>
        <CLM Claimid="3"  DateOfService="01/02/2011"
         EndOfService="05/05/2011" ServiceId="S2"
         WorkerName="WORK1" WorkerId="2006"
         Unit= '7' Amount= '5000'/>
        <CLM Claimid="4"  DateOfService="01/03/2011"
         EndOfService="05/05/2011" ServiceId="S1"
         WorkerName="WOK2" WorkerId="6446"
         Unit= '3' Amount= '5000'/>
        <CLM Claimid="5"  DateOfService="01/03/2011"
         EndOfService="05/05/2011" ServiceId="S2"
         WorkerName="WORK2" WorkerId="6446"
         Unit= '8' Amount= '5000'/>
        <CLM Claimid="6" DateOfService="01/03/2011"
         EndOfService="05/05/2011" ServiceId="S2"
         WorkerName="WORK1" WorkerId="6446"
         Unit= '1' Amount= '5000'/>
    </CLT>
    <CLT ClientId="4444" ClientFName="John"
      ClientLastName="Pulaski" Phone="56462561">
        <CLM Claimid="1"  DateOfService="01/02/2011"
          EndOfService="05/05/2011" ServiceId="S1"
          WorkerName="WORK1" WorkerId="6446"
         Unit= '5' Amount= '5000'/>
    </CLT>
</PRV>

xsl 应用于此输入,

<xsl:stylesheet version="1.0"
 xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output omit-xml-declaration="yes" indent="yes"/>
    <xsl:strip-space elements="*"/>

    <xsl:key name="kCLMByAttribs" match="CLM" use=
 "concat(@ServiceId,'+',@WorkerId,'+',@DateOfService)"/>

    <xsl:template match="node()|@*">
        <xsl:copy>
            <xsl:apply-templates select="node()|@*"/>
        </xsl:copy>
    </xsl:template>

    <xsl:template match=
 "CLM[generate-id()
     =
      generate-id(key('kCLMByAttribs',
                      concat(@ServiceId,
                            '+',@WorkerId,
                            '+',@DateOfService)
                     )
                     [1]
                 )
     ]
 ">
        <xsl:copy>
            <xsl:copy-of select="@*"/>

            <xsl:variable name="vGroup" select=
   "key('kCLMByAttribs',
         concat(@ServiceId,
                '+',@WorkerId,
                '+',@DateOfService)
       )
   "/>

            <xsl:variable name="vClaimIds">
                <xsl:for-each select="$vGroup">
                    <xsl:if test="not(position()=1)">
                        <xsl:value-of select="','"/>
                    </xsl:if>
                    <xsl:value-of select="@Claimid"/>
                </xsl:for-each>
            </xsl:variable>

            <xsl:attribute name="Claimid">
                <xsl:value-of select="$vClaimIds"/>
            </xsl:attribute>

            <xsl:attribute name="Unit">
                <xsl:value-of select="sum($vGroup/@Unit)"/>
            </xsl:attribute>
        </xsl:copy>
    </xsl:template>

    <xsl:template match="CLM"/>
</xsl:stylesheet>

所需的输出

<PRV ProviderId="100" PName="Giga health" Provsuv="1563">
  <CLT ClientId="4444" ClientFName="John" ClientLastName="Pulaski" Phone="56462561">
    <CLM DateOfService="01/02/2011" EndOfService="05/05/2011" ServiceId="S1" WorkerName="WORK1" WorkerId="6446" Amount="5000" Claimid="1,2" Unit="16" />
    <CLM DateOfService="01/02/2011" EndOfService="05/05/2011" ServiceId="S2" WorkerName="WORK1" WorkerId="2006" Amount="5000" Claimid="3" Unit="7" />
    <CLM DateOfService="01/03/2011" EndOfService="05/05/2011" ServiceId="S1" WorkerName="WOK2" WorkerId="6446" Amount="5000" Claimid="4" Unit="3" />
    <CLM DateOfService="01/03/2011" EndOfService="05/05/2011" ServiceId="S2" WorkerName="WORK2" WorkerId="6446" Amount="5000" Claimid="5,6" Unit="9" />
  </CLT>
  <CLT ClientId="4444" ClientFName="John" ClientLastName="Pulaski" Phone="56462561">
      <CLM Claimid="1"  DateOfService="01/02/2011" EndOfService="05/05/2011" ServiceId="S1" WorkerName="WORK1" WorkerId="6446" Unit= '5' Amount= '5000'/>
  </CLT>  
</PRV>

I know this might be simple but i tried a lot to find answer by looking at some similar questions like this. The meunchian grouping with concat of 3 keys works fine, but what if the input does not require to be grouped. I have provided sample xsl below.The output i get when i run the transform does not create the CLM node if there is only one occurence of CLM node. Thanks in advance.

the input file

<?xml version="1.0" encoding="utf-8"?>
<PRV ProviderId="100" PName="Giga health"
Provsuv="1563">
    <CLT ClientId="4444" ClientFName="John"
      ClientLastName="Pulaski" Phone="56462561">
        <CLM Claimid="1"  DateOfService="01/02/2011"
          EndOfService="05/05/2011" ServiceId="S1"
          WorkerName="WORK1" WorkerId="6446"
          Unit= '5' Amount= '5000'/>
        <CLM Claimid="2"  DateOfService="01/02/2011"
         EndOfService="05/05/2011" ServiceId="S1"
         WorkerName="WORK1" WorkerId="6446"
         Unit= '6' Amount= '5000'/>
        <CLM Claimid="3"  DateOfService="01/02/2011"
         EndOfService="05/05/2011" ServiceId="S2"
         WorkerName="WORK1" WorkerId="2006"
         Unit= '7' Amount= '5000'/>
        <CLM Claimid="4"  DateOfService="01/03/2011"
         EndOfService="05/05/2011" ServiceId="S1"
         WorkerName="WOK2" WorkerId="6446"
         Unit= '3' Amount= '5000'/>
        <CLM Claimid="5"  DateOfService="01/03/2011"
         EndOfService="05/05/2011" ServiceId="S2"
         WorkerName="WORK2" WorkerId="6446"
         Unit= '8' Amount= '5000'/>
        <CLM Claimid="6" DateOfService="01/03/2011"
         EndOfService="05/05/2011" ServiceId="S2"
         WorkerName="WORK1" WorkerId="6446"
         Unit= '1' Amount= '5000'/>
    </CLT>
    <CLT ClientId="4444" ClientFName="John"
      ClientLastName="Pulaski" Phone="56462561">
        <CLM Claimid="1"  DateOfService="01/02/2011"
          EndOfService="05/05/2011" ServiceId="S1"
          WorkerName="WORK1" WorkerId="6446"
         Unit= '5' Amount= '5000'/>
    </CLT>
</PRV>

the xsl applied to this input,

<xsl:stylesheet version="1.0"
 xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output omit-xml-declaration="yes" indent="yes"/>
    <xsl:strip-space elements="*"/>

    <xsl:key name="kCLMByAttribs" match="CLM" use=
 "concat(@ServiceId,'+',@WorkerId,'+',@DateOfService)"/>

    <xsl:template match="node()|@*">
        <xsl:copy>
            <xsl:apply-templates select="node()|@*"/>
        </xsl:copy>
    </xsl:template>

    <xsl:template match=
 "CLM[generate-id()
     =
      generate-id(key('kCLMByAttribs',
                      concat(@ServiceId,
                            '+',@WorkerId,
                            '+',@DateOfService)
                     )
                     [1]
                 )
     ]
 ">
        <xsl:copy>
            <xsl:copy-of select="@*"/>

            <xsl:variable name="vGroup" select=
   "key('kCLMByAttribs',
         concat(@ServiceId,
                '+',@WorkerId,
                '+',@DateOfService)
       )
   "/>

            <xsl:variable name="vClaimIds">
                <xsl:for-each select="$vGroup">
                    <xsl:if test="not(position()=1)">
                        <xsl:value-of select="','"/>
                    </xsl:if>
                    <xsl:value-of select="@Claimid"/>
                </xsl:for-each>
            </xsl:variable>

            <xsl:attribute name="Claimid">
                <xsl:value-of select="$vClaimIds"/>
            </xsl:attribute>

            <xsl:attribute name="Unit">
                <xsl:value-of select="sum($vGroup/@Unit)"/>
            </xsl:attribute>
        </xsl:copy>
    </xsl:template>

    <xsl:template match="CLM"/>
</xsl:stylesheet>

The desired output

<PRV ProviderId="100" PName="Giga health" Provsuv="1563">
  <CLT ClientId="4444" ClientFName="John" ClientLastName="Pulaski" Phone="56462561">
    <CLM DateOfService="01/02/2011" EndOfService="05/05/2011" ServiceId="S1" WorkerName="WORK1" WorkerId="6446" Amount="5000" Claimid="1,2" Unit="16" />
    <CLM DateOfService="01/02/2011" EndOfService="05/05/2011" ServiceId="S2" WorkerName="WORK1" WorkerId="2006" Amount="5000" Claimid="3" Unit="7" />
    <CLM DateOfService="01/03/2011" EndOfService="05/05/2011" ServiceId="S1" WorkerName="WOK2" WorkerId="6446" Amount="5000" Claimid="4" Unit="3" />
    <CLM DateOfService="01/03/2011" EndOfService="05/05/2011" ServiceId="S2" WorkerName="WORK2" WorkerId="6446" Amount="5000" Claimid="5,6" Unit="9" />
  </CLT>
  <CLT ClientId="4444" ClientFName="John" ClientLastName="Pulaski" Phone="56462561">
      <CLM Claimid="1"  DateOfService="01/02/2011" EndOfService="05/05/2011" ServiceId="S1" WorkerName="WORK1" WorkerId="6446" Unit= '5' Amount= '5000'/>
  </CLT>  
</PRV>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

屋顶上的小猫咪 2024-11-16 15:15:59

获得预期结果的最简单的更改是让您的密钥包含 generate-id(..)

<PRV ProviderId="100" PName="Giga health" Provsuv="1563">
  <CLT ClientId="4444" ClientFName="John" ClientLastName="Pulaski" Phone="56462561">
    <CLM Claimid="1,2" DateOfService="01/02/2011" EndOfService="05/05/2011" ServiceId="S1" WorkerName="WORK1" WorkerId="6446" Unit="11" Amount="5000"/>
    <CLM Claimid="3" DateOfService="01/02/2011" EndOfService="05/05/2011" ServiceId="S2" WorkerName="WORK1" WorkerId="2006" Unit="7" Amount="5000"/>
    <CLM Claimid="4" DateOfService="01/03/2011" EndOfService="05/05/2011" ServiceId="S1" WorkerName="WOK2" WorkerId="6446" Unit="3" Amount="5000"/>
    <CLM Claimid="5,6" DateOfService="01/03/2011" EndOfService="05/05/2011" ServiceId="S2" WorkerName="WORK2" WorkerId="6446" Unit="9" Amount="5000"/>
  </CLT>
  <CLT ClientId="4444" ClientFName="John" ClientLastName="Pulaski" Phone="56462561">
    <CLM Claimid="1" DateOfService="01/02/2011" EndOfService="05/05/2011" ServiceId="S1" WorkerName="WORK1" WorkerId="6446" Unit="5" Amount="5000"/>
  </CLT>
</PRV>

请注意,这会导致 Claimid="1,2"第一个 CLT 节点下的第一个 CLM 节点,因为我认为这是您想要的。

The easiest change to get your expected result would be to let your key include generate-id(..):

<PRV ProviderId="100" PName="Giga health" Provsuv="1563">
  <CLT ClientId="4444" ClientFName="John" ClientLastName="Pulaski" Phone="56462561">
    <CLM Claimid="1,2" DateOfService="01/02/2011" EndOfService="05/05/2011" ServiceId="S1" WorkerName="WORK1" WorkerId="6446" Unit="11" Amount="5000"/>
    <CLM Claimid="3" DateOfService="01/02/2011" EndOfService="05/05/2011" ServiceId="S2" WorkerName="WORK1" WorkerId="2006" Unit="7" Amount="5000"/>
    <CLM Claimid="4" DateOfService="01/03/2011" EndOfService="05/05/2011" ServiceId="S1" WorkerName="WOK2" WorkerId="6446" Unit="3" Amount="5000"/>
    <CLM Claimid="5,6" DateOfService="01/03/2011" EndOfService="05/05/2011" ServiceId="S2" WorkerName="WORK2" WorkerId="6446" Unit="9" Amount="5000"/>
  </CLT>
  <CLT ClientId="4444" ClientFName="John" ClientLastName="Pulaski" Phone="56462561">
    <CLM Claimid="1" DateOfService="01/02/2011" EndOfService="05/05/2011" ServiceId="S1" WorkerName="WORK1" WorkerId="6446" Unit="5" Amount="5000"/>
  </CLT>
</PRV>

Note that this results in Claimid="1,2" for the first CLM node under the first CLT node, as this as what I assume you want.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文