XSLT Muenchian grouping from BizTalk WCF-SQL adapter schema by group identifier

I am working on a BizTalk application that does typed polling from a database using the WCF SQL adapter. After learning how to group data from a generated schema into my canonical schema, I met Muenchian Grouping as a general solution. However, it is difficult for me to determine how to apply it to my situation.

Basically, the data I'm looking at is spread across several tables, which are a combination of one-to-one and one-to-many relationships that use the same primary key in all tables. Due to the one-to-many relationship, I cannot extract all the data from different tables using a single SELECT statement, and decided instead to split it into multiple queries in my Polling Data report, which generated the source schema shown in the image below .

What I'm trying to do is simply separate all the records from my source schema from the "SharedID" and put them in the corresponding record in my target schema. (I also have a secondary instance number identifier for the subgroups, but I would assume that they will be resolved in the same way.) All the examples I saw show how to do this when the XSLT key is obtained from a single node or several nodes from the original circuit, but they don’t show how to account when the same identifier comes from multiple nodes.

I have analyzed examples from as many sources as possible, but I'm still not familiar with XSLT, so it's hard for me to determine how to configure my keys and each statement to use this approach. Any help promoting demystification, how should I do this, would be greatly appreciated. Thank!

Here is a screenshot of the map using generalized versions of the structure of the source and target circuits.

enter image description here

Here is the XSLT that the map above generates, which I use as a starting point.

<?xml version="1.0" encoding="UTF-16"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                xmlns:msxsl="urn:schemas-microsoft-com:xslt"
                xmlns:var="http://schemas.microsoft.com/BizTalk/2003/var"
                exclude-result-prefixes="msxsl var s0"
                version="1.0"
                xmlns:s0="http://SmallGenericSchemaTest.Schemas/SourceSchema"
                xmlns:ns0="http://SmallGenericSchemaTest.Schemas/DestinationSchema">
    <xsl:output omit-xml-declaration="yes" method="xml" version="1.0" />

    <xsl:template match="/">
        <xsl:apply-templates select="/s0:TypedPolling" />
    </xsl:template>

    <xsl:template match="/s0:TypedPolling">
        <ns0:AllRecords>
            <ns0:SingleRecord>
                <xsl:for-each select="s0:TypedPollingResultSet0">
                    <xsl:for-each select="s0:TypedPollingResultSet0">
                        <ns0:GroupA>
                            <xsl:if test="s0:SharedID">
                                <ns0:SharedID>
                                    <xsl:value-of select="s0:SharedID/text()" />
                                </ns0:SharedID>
                            </xsl:if>

                            <xsl:if test="s0:MiscInfoA1">
                                <ns0:MiscInfoA1>
                                    <xsl:value-of select="s0:MiscInfoA1/text()" />
                                </ns0:MiscInfoA1>
                            </xsl:if>

                            <xsl:if test="s0:MiscInfoA2">
                                <ns0:MiscInfoA2>
                                    <xsl:value-of select="s0:MiscInfoA2/text()" />
                                </ns0:MiscInfoA2>
                            </xsl:if>
                        </ns0:GroupA>
                    </xsl:for-each>
                </xsl:for-each>

                <xsl:for-each select="s0:TypedPollingResultSet1">
                    <xsl:for-each select="s0:TypedPollingResultSet1">
                        <ns0:GroupB>
                            <xsl:if test="s0:MiscInfoB1">
                                <ns0:MiscInfoB1>
                                    <xsl:value-of select="s0:MiscInfoB1/text()" />
                                </ns0:MiscInfoB1>
                            </xsl:if>

                            <xsl:if test="s0:MiscInfoB2">
                                <ns0:MiscInfoB2>
                                    <xsl:value-of select="s0:MiscInfoB2/text()" />
                                </ns0:MiscInfoB2>
                            </xsl:if>

                            <ns0:SubGroupBAContainer>
                                <xsl:for-each select="../../s0:TypedPollingResultSet2">
                                    <xsl:for-each select="s0:TypedPollingResultSet2">
                                        <ns0:SubGroupBA>
                                            <xsl:if test="s0:MiscInfoBA1">
                                                <ns0:MiscInfoBA1>
                                                    <xsl:value-of select="s0:MiscInfoBA1/text()" />
                                                </ns0:MiscInfoBA1>
                                            </xsl:if>

                                            <xsl:if test="s0:MiscInfoBA2">
                                                <ns0:MiscInfoBA2>
                                                    <xsl:value-of select="s0:MiscInfoBA2/text()" />
                                                </ns0:MiscInfoBA2>
                                            </xsl:if>
                                        </ns0:SubGroupBA>
                                    </xsl:for-each>
                                </xsl:for-each>
                            </ns0:SubGroupBAContainer>

                            <ns0:SubGroupBBContainer>
                                <xsl:for-each select="../../s0:TypedPollingResultSet3">
                                    <xsl:for-each select="s0:TypedPollingResultSet3">
                                        <ns0:SubGroupBB>
                                            <xsl:if test="s0:MiscInfoBB1">
                                                <ns0:MiscInfoBB1>
                                                    <xsl:value-of select="s0:MiscInfoBB1/text()" />
                                                </ns0:MiscInfoBB1>
                                            </xsl:if>

                                            <xsl:if test="s0:MiscInfoBB2">
                                                <ns0:MiscInfoBB2>
                                                    <xsl:value-of select="s0:MiscInfoBB2/text()" />
                                                </ns0:MiscInfoBB2>
                                            </xsl:if>
                                        </ns0:SubGroupBB>
                                    </xsl:for-each>
                                </xsl:for-each>
                            </ns0:SubGroupBBContainer>
                        </ns0:GroupB>
                    </xsl:for-each>
                </xsl:for-each>

                <ns0:GroupCContainer>
                    <xsl:for-each select="s0:TypedPollingResultSet4">
                        <xsl:for-each select="s0:TypedPollingResultSet4">
                            <ns0:GroupC>
                                <xsl:if test="s0:GroupCInstanceID">
                                    <ns0:GroupCInstanceID>
                                        <xsl:value-of select="s0:GroupCInstanceID/text()" />
                                    </ns0:GroupCInstanceID>
                                </xsl:if>

                                <xsl:if test="s0:MiscInfoC1">
                                    <ns0:MiscInfoC1>
                                        <xsl:value-of select="s0:MiscInfoC1/text()" />
                                    </ns0:MiscInfoC1>
                                </xsl:if>

                                <xsl:if test="s0:MiscInfoC2">
                                    <ns0:MiscInfoC2>
                                        <xsl:value-of select="s0:MiscInfoC2/text()" />
                                    </ns0:MiscInfoC2>
                                </xsl:if>
                            </ns0:GroupC>
                        </xsl:for-each>
                    </xsl:for-each>
                </ns0:GroupCContainer>

                <ns0:GroupDContainer>
                    <xsl:for-each select="s0:TypedPollingResultSet5">
                        <xsl:for-each select="s0:TypedPollingResultSet5">
                            <ns0:GroupD>
                                <xsl:if test="s0:GroupDInstanceID">
                                    <ns0:GroupDInstanceID>
                                        <xsl:value-of select="s0:GroupDInstanceID/text()" />
                                    </ns0:GroupDInstanceID>
                                </xsl:if>

                                <xsl:if test="s0:MiscInfoD1">
                                    <ns0:MiscInfoD1>
                                        <xsl:value-of select="s0:MiscInfoD1/text()" />
                                    </ns0:MiscInfoD1>
                                </xsl:if>

                                <xsl:if test="s0:MiscInfoD2">
                                    <ns0:MiscInfoD2>
                                        <xsl:value-of select="s0:MiscInfoD2/text()" />
                                    </ns0:MiscInfoD2>
                                </xsl:if>
                                <xsl:for-each select="../../s0:TypedPollingResultSet6">
                                    <xsl:for-each select="s0:TypedPollingResultSet6">
                                        <ns0:SubGroupDA>
                                            <xsl:if test="s0:MiscInfoDA1">
                                                <ns0:MiscInfoDA1>
                                                    <xsl:value-of select="s0:MiscInfoDA1/text()" />
                                                </ns0:MiscInfoDA1>
                                            </xsl:if>

                                            <xsl:if test="s0:MiscInfoDA2">
                                                <ns0:MiscInfoDA2>
                                                    <xsl:value-of select="s0:MiscInfoDA2/text()" />
                                                </ns0:MiscInfoDA2>
                                            </xsl:if>
                                        </ns0:SubGroupDA>
                                    </xsl:for-each>
                                </xsl:for-each>

                                <ns0:SubGroupDBContainer>
                                    <xsl:for-each select="../../s0:TypedPollingResultSet7">
                                        <xsl:for-each select="s0:TypedPollingResultSet7">
                                            <ns0:SubGroupDB>
                                                <xsl:if test="s0:MiscInfoDB1">
                                                    <ns0:MiscInfoDB1>
                                                        <xsl:value-of select="s0:MiscInfoDB1/text()" />
                                                    </ns0:MiscInfoDB1>
                                                </xsl:if>

                                                <xsl:if test="s0:MiscInfoDB2">
                                                    <ns0:MiscInfoDB2>
                                                        <xsl:value-of select="s0:MiscInfoDB2/text()" />
                                                    </ns0:MiscInfoDB2>
                                                </xsl:if>
                                            </ns0:SubGroupDB>
                                        </xsl:for-each>
                                    </xsl:for-each>
                                </ns0:SubGroupDBContainer>
                            </ns0:GroupD>
                        </xsl:for-each>
                    </xsl:for-each>
                </ns0:GroupDContainer>
            </ns0:SingleRecord>
        </ns0:AllRecords>
    </xsl:template>
</xsl:stylesheet>

EDIT:

Here is an example input of an xml document and the desired output.

Input Example:

<ns0:TypedPolling xmlns:ns0="http://SmallGenericSchemaTest.Schemas/SourceSchema">
    <ns0:TypedPollingResultSet0>
        <ns0:TypedPollingResultSet0>
            <ns0:SharedID>SharedID_1</ns0:SharedID>
            <ns0:MiscInfoA1>A1_1</ns0:MiscInfoA1>
            <ns0:MiscInfoA2>A2_1</ns0:MiscInfoA2>
        </ns0:TypedPollingResultSet0>

        <ns0:TypedPollingResultSet0>
            <ns0:SharedID>SharedID_2</ns0:SharedID>
            <ns0:MiscInfoA1>A1_2</ns0:MiscInfoA1>
            <ns0:MiscInfoA2>A2_2</ns0:MiscInfoA2>
        </ns0:TypedPollingResultSet0>
    </ns0:TypedPollingResultSet0>

    <ns0:TypedPollingResultSet1>
        <ns0:TypedPollingResultSet1>
            <ns0:SharedID>SharedID_1</ns0:SharedID>
            <ns0:MiscInfoB1>B1_1</ns0:MiscInfoB1>
            <ns0:MiscInfoB2>B2_1</ns0:MiscInfoB2>
        </ns0:TypedPollingResultSet1>

        <ns0:TypedPollingResultSet1>
            <ns0:SharedID>SharedID_2</ns0:SharedID>
            <ns0:MiscInfoB1>B1_2</ns0:MiscInfoB1>
            <ns0:MiscInfoB2>B2_2</ns0:MiscInfoB2>
        </ns0:TypedPollingResultSet1>
    </ns0:TypedPollingResultSet1>

    <ns0:TypedPollingResultSet2>
        <ns0:TypedPollingResultSet2>
            <ns0:SharedID>SharedID_1</ns0:SharedID>
            <ns0:MiscInfoBA1>BA1_1A</ns0:MiscInfoBA1>
            <ns0:MiscInfoBA2>BA2_1A</ns0:MiscInfoBA2>
        </ns0:TypedPollingResultSet2>

        <ns0:TypedPollingResultSet2>
            <ns0:SharedID>SharedID_1</ns0:SharedID>
            <ns0:MiscInfoBA1>BA1_1B</ns0:MiscInfoBA1>
            <ns0:MiscInfoBA2>BA2_1B</ns0:MiscInfoBA2>
        </ns0:TypedPollingResultSet2>

        <ns0:TypedPollingResultSet2>
            <ns0:SharedID>SharedID_2</ns0:SharedID>
            <ns0:MiscInfoBA1>BA1_2A</ns0:MiscInfoBA1>
            <ns0:MiscInfoBA2>BA2_2A</ns0:MiscInfoBA2>
        </ns0:TypedPollingResultSet2>

        <ns0:TypedPollingResultSet2>
            <ns0:SharedID>SharedID_2</ns0:SharedID>
            <ns0:MiscInfoBA1>BA1_2B</ns0:MiscInfoBA1>
            <ns0:MiscInfoBA2>BA2_2B</ns0:MiscInfoBA2>
        </ns0:TypedPollingResultSet2>
    </ns0:TypedPollingResultSet2>

    <ns0:TypedPollingResultSet3>
        <ns0:TypedPollingResultSet3>
            <ns0:SharedID>SharedID_1</ns0:SharedID>
            <ns0:MiscInfoBB1>BB1_1A</ns0:MiscInfoBB1>
            <ns0:MiscInfoBB2>BB2_1A</ns0:MiscInfoBB2>
        </ns0:TypedPollingResultSet3>

        <ns0:TypedPollingResultSet3>
            <ns0:SharedID>SharedID_1</ns0:SharedID>
            <ns0:MiscInfoBB1>BB1_1B</ns0:MiscInfoBB1>
            <ns0:MiscInfoBB2>BB2_1B</ns0:MiscInfoBB2>
        </ns0:TypedPollingResultSet3>

        <ns0:TypedPollingResultSet3>
            <ns0:SharedID>SharedID_2</ns0:SharedID>
            <ns0:MiscInfoBB1>BB1_2</ns0:MiscInfoBB1>
            <ns0:MiscInfoBB2>BB2_2</ns0:MiscInfoBB2>
        </ns0:TypedPollingResultSet3>
    </ns0:TypedPollingResultSet3>

    <ns0:TypedPollingResultSet4>
        <ns0:TypedPollingResultSet4>
            <ns0:SharedID>SharedID_1</ns0:SharedID>
            <ns0:GroupCInstanceID>GroupCInstanceID_1A</ns0:GroupCInstanceID>
            <ns0:MiscInfoC1>C1_1A</ns0:MiscInfoC1>
            <ns0:MiscInfoC2>C2_1A</ns0:MiscInfoC2>
        </ns0:TypedPollingResultSet4>

        <ns0:TypedPollingResultSet4>
            <ns0:SharedID>SharedID_1</ns0:SharedID>
            <ns0:GroupCInstanceID>GroupCInstanceID_1B</ns0:GroupCInstanceID>
            <ns0:MiscInfoC1>C1_1B</ns0:MiscInfoC1>
            <ns0:MiscInfoC2>C2_1B</ns0:MiscInfoC2>
        </ns0:TypedPollingResultSet4>

        <ns0:TypedPollingResultSet4>
            <ns0:SharedID>SharedID_2</ns0:SharedID>
            <ns0:GroupCInstanceID>GroupCInstanceID_2</ns0:GroupCInstanceID>
            <ns0:MiscInfoC1>C1_2</ns0:MiscInfoC1>
            <ns0:MiscInfoC2>C2_2</ns0:MiscInfoC2>
        </ns0:TypedPollingResultSet4>
    </ns0:TypedPollingResultSet4>

    <ns0:TypedPollingResultSet5>
        <ns0:TypedPollingResultSet5>
            <ns0:SharedID>SharedID_1</ns0:SharedID>
            <ns0:GroupDInstanceID>GroupDInstanceID_1A</ns0:GroupDInstanceID>
            <ns0:MiscInfoD1>D1_1A</ns0:MiscInfoD1>
            <ns0:MiscInfoD2>D2_1A</ns0:MiscInfoD2>
        </ns0:TypedPollingResultSet5>

        <ns0:TypedPollingResultSet5>
            <ns0:SharedID>SharedID_1</ns0:SharedID>
            <ns0:GroupDInstanceID>GroupDInstanceID_1B</ns0:GroupDInstanceID>
            <ns0:MiscInfoD1>D1_1B</ns0:MiscInfoD1>
            <ns0:MiscInfoD2>D2_1B</ns0:MiscInfoD2>
        </ns0:TypedPollingResultSet5>

        <ns0:TypedPollingResultSet5>
            <ns0:SharedID>SharedID_2</ns0:SharedID>
            <ns0:GroupDInstanceID>GroupDInstanceID_2</ns0:GroupDInstanceID>
            <ns0:MiscInfoD1>D1_2</ns0:MiscInfoD1>
            <ns0:MiscInfoD2>D2_2</ns0:MiscInfoD2>
        </ns0:TypedPollingResultSet5>
    </ns0:TypedPollingResultSet5>

    <ns0:TypedPollingResultSet6>
        <ns0:TypedPollingResultSet6>
            <ns0:SharedID>SharedID_1</ns0:SharedID>
            <ns0:GroupDInstanceID>GroupDInstanceID_1A</ns0:GroupDInstanceID>
            <ns0:MiscInfoDA1>DA1_1A</ns0:MiscInfoDA1>
            <ns0:MiscInfoDA2>DA2_1A</ns0:MiscInfoDA2>
        </ns0:TypedPollingResultSet6>

        <ns0:TypedPollingResultSet6>
            <ns0:SharedID>SharedID_1</ns0:SharedID>
            <ns0:GroupDInstanceID>GroupDInstanceID_1B</ns0:GroupDInstanceID>
            <ns0:MiscInfoDA1>DA1_1B</ns0:MiscInfoDA1>
            <ns0:MiscInfoDA2>DA2_1B</ns0:MiscInfoDA2>
        </ns0:TypedPollingResultSet6>

        <ns0:TypedPollingResultSet6>
            <ns0:SharedID>SharedID_2</ns0:SharedID>
            <ns0:GroupDInstanceID>GroupDInstanceID_2</ns0:GroupDInstanceID>
            <ns0:MiscInfoDA1>DA1_2</ns0:MiscInfoDA1>
            <ns0:MiscInfoDA2>DA2_2</ns0:MiscInfoDA2>
        </ns0:TypedPollingResultSet6>
    </ns0:TypedPollingResultSet6>

    <ns0:TypedPollingResultSet7>
        <ns0:TypedPollingResultSet7>
            <ns0:SharedID>SharedID_1</ns0:SharedID>
            <ns0:GroupDInstanceID>GroupDInstanceID_1A</ns0:GroupDInstanceID>
            <ns0:MiscInfoDB1>DB1_1A</ns0:MiscInfoDB1>
            <ns0:MiscInfoDB2>DB2_1A</ns0:MiscInfoDB2>
        </ns0:TypedPollingResultSet7>

        <ns0:TypedPollingResultSet7>
            <ns0:SharedID>SharedID_1</ns0:SharedID>
            <ns0:GroupDInstanceID>GroupDInstanceID_1B</ns0:GroupDInstanceID>
            <ns0:MiscInfoDB1>DB1_1B</ns0:MiscInfoDB1>
            <ns0:MiscInfoDB2>DB2_1B</ns0:MiscInfoDB2>
        </ns0:TypedPollingResultSet7>

        <ns0:TypedPollingResultSet7>
            <ns0:SharedID>SharedID_2</ns0:SharedID>
            <ns0:GroupDInstanceID>GroupDInstanceID_2</ns0:GroupDInstanceID>
            <ns0:MiscInfoDB1>DB1_2</ns0:MiscInfoDB1>
            <ns0:MiscInfoDB2>DB2_2</ns0:MiscInfoDB2>
        </ns0:TypedPollingResultSet7>
    </ns0:TypedPollingResultSet7>
</ns0:TypedPolling>

Required Conclusion:

<ns0:AllRecords xmlns:ns0="http://SmallGenericSchemaTest.Schemas/DestinationSchema">
    <ns0:SingleRecord>
        <ns0:GroupA>
            <ns0:SharedID>SharedID_1</ns0:SharedID>
            <ns0:MiscInfoA1>A1_1</ns0:MiscInfoA1>
            <ns0:MiscInfoA2>A2_1</ns0:MiscInfoA2>
        </ns0:GroupA>

        <ns0:GroupB>
            <ns0:MiscInfoB1>B1_1</ns0:MiscInfoB1>
            <ns0:MiscInfoB2>B2_1</ns0:MiscInfoB2>

            <ns0:SubGroupBAContainer>
                <ns0:SubGroupBA>
                    <ns0:MiscInfoBA1>BA1_1A</ns0:MiscInfoBA1>
                    <ns0:MiscInfoBA2>BA2_1A</ns0:MiscInfoBA2>
                </ns0:SubGroupBA>

                <ns0:SubGroupBA>
                    <ns0:MiscInfoBA1>BA1_1B</ns0:MiscInfoBA1>
                    <ns0:MiscInfoBA2>BA2_1B</ns0:MiscInfoBA2>
                </ns0:SubGroupBA>
            </ns0:SubGroupBAContainer>

            <ns0:SubGroupBBContainer>
                <ns0:SubGroupBB>
                    <ns0:MiscInfoBB1>BB1_1A</ns0:MiscInfoBB1>
                    <ns0:MiscInfoBB2>BB2_1A</ns0:MiscInfoBB2>
                </ns0:SubGroupBB>

                <ns0:SubGroupBB>
                    <ns0:MiscInfoBB1>BB1_1B</ns0:MiscInfoBB1>
                    <ns0:MiscInfoBB2>BB2_1B</ns0:MiscInfoBB2>
                </ns0:SubGroupBB>
            </ns0:SubGroupBBContainer>
        </ns0:GroupB>

        <ns0:GroupCContainer>
            <ns0:GroupC>
                <ns0:GroupCInstanceID>GroupCInstanceID_1A</ns0:GroupCInstanceID>
                <ns0:MiscInfoC1>C1_1A</ns0:MiscInfoC1>
                <ns0:MiscInfoC2>C2_1A</ns0:MiscInfoC2>
            </ns0:GroupC>

            <ns0:GroupC>
                <ns0:GroupCInstanceID>GroupCInstanceID_1B</ns0:GroupCInstanceID>
                <ns0:MiscInfoC1>C1_1B</ns0:MiscInfoC1>
                <ns0:MiscInfoC2>C2_1B</ns0:MiscInfoC2>
            </ns0:GroupC>
        </ns0:GroupCContainer>

        <ns0:GroupDContainer>
            <ns0:GroupD>
                <ns0:GroupDInstanceID>GroupDInstanceID_1A</ns0:GroupDInstanceID>
                <ns0:MiscInfoD1>D1_1A</ns0:MiscInfoD1>
                <ns0:MiscInfoD2>D2_1A</ns0:MiscInfoD2>

                <ns0:SubGroupDA>
                    <ns0:MiscInfoDA1>DA1_1A</ns0:MiscInfoDA1>
                    <ns0:MiscInfoDA2>DA2_1A</ns0:MiscInfoDA2>
                </ns0:SubGroupDA>

                <ns0:SubGroupDBContainer>
                    <ns0:SubGroupDB>
                        <ns0:MiscInfoDB1>DB1_1A</ns0:MiscInfoDB1>
                        <ns0:MiscInfoDB2>DB2_1A</ns0:MiscInfoDB2>
                    </ns0:SubGroupDB>
                </ns0:SubGroupDBContainer>
            </ns0:GroupD>

            <ns0:GroupD>
                <ns0:GroupDInstanceID>GroupDInstanceID_1B</ns0:GroupDInstanceID>
                <ns0:MiscInfoD1>D1_1B</ns0:MiscInfoD1>
                <ns0:MiscInfoD2>D2_1B</ns0:MiscInfoD2>

                <ns0:SubGroupDA>
                    <ns0:MiscInfoDA1>DA1_1B</ns0:MiscInfoDA1>
                    <ns0:MiscInfoDA2>DA2_1B</ns0:MiscInfoDA2>
                </ns0:SubGroupDA>

                <ns0:SubGroupDBContainer>
                    <ns0:SubGroupDB>
                        <ns0:MiscInfoDB1>DB1_1B</ns0:MiscInfoDB1>
                        <ns0:MiscInfoDB2>DB2_1B</ns0:MiscInfoDB2>
                    </ns0:SubGroupDB>
                </ns0:SubGroupDBContainer>
            </ns0:GroupD>
        </ns0:GroupDContainer>
    </ns0:SingleRecord>

    <ns0:SingleRecord>
        <ns0:GroupA>
            <ns0:SharedID>SharedID_2</ns0:SharedID>
            <ns0:MiscInfoA1>A1_2</ns0:MiscInfoA1>
            <ns0:MiscInfoA2>A2_2</ns0:MiscInfoA2>
        </ns0:GroupA>

        <ns0:GroupB>
            <ns0:MiscInfoB1>B1_2</ns0:MiscInfoB1>
            <ns0:MiscInfoB2>B2_2</ns0:MiscInfoB2>

            <ns0:SubGroupBAContainer>
                <ns0:SubGroupBA>
                    <ns0:MiscInfoBA1>BA1_2A</ns0:MiscInfoBA1>
                    <ns0:MiscInfoBA2>BA2_2A</ns0:MiscInfoBA2>
                </ns0:SubGroupBA>

                <ns0:SubGroupBA>
                    <ns0:MiscInfoBA1>BA1_2B</ns0:MiscInfoBA1>
                    <ns0:MiscInfoBA2>BA2_2B</ns0:MiscInfoBA2>
                </ns0:SubGroupBA>
            </ns0:SubGroupBAContainer>

            <ns0:SubGroupBBContainer>
                <ns0:SubGroupBB>
                    <ns0:MiscInfoBB1>BB1_2</ns0:MiscInfoBB1>
                    <ns0:MiscInfoBB2>BB2_2</ns0:MiscInfoBB2>
                </ns0:SubGroupBB>
            </ns0:SubGroupBBContainer>
        </ns0:GroupB>

        <ns0:GroupCContainer>
            <ns0:GroupC>
                <ns0:GroupCInstanceID>GroupCInstanceID_2</ns0:GroupCInstanceID>
                <ns0:MiscInfoC1>C1_2</ns0:MiscInfoC1>
                <ns0:MiscInfoC2>C2_2</ns0:MiscInfoC2>
            </ns0:GroupC>
        </ns0:GroupCContainer>

        <ns0:GroupDContainer>
            <ns0:GroupD>
                <ns0:GroupDInstanceID>GroupDInstanceID_2</ns0:GroupDInstanceID>
                <ns0:MiscInfoD1>D1_2</ns0:MiscInfoD1>
                <ns0:MiscInfoD2>D2_2</ns0:MiscInfoD2>

                <ns0:SubGroupDA>
                    <ns0:MiscInfoDA1>DA1_2</ns0:MiscInfoDA1>
                    <ns0:MiscInfoDA2>DA2_2</ns0:MiscInfoDA2>
                </ns0:SubGroupDA>

                <ns0:SubGroupDBContainer>
                    <ns0:SubGroupDB>
                        <ns0:MiscInfoDB1>DB1_2</ns0:MiscInfoDB1>
                        <ns0:MiscInfoDB2>DB2_2</ns0:MiscInfoDB2>
                    </ns0:SubGroupDB>
                </ns0:SubGroupDBContainer>
            </ns0:GroupD>
        </ns0:GroupDContainer>
    </ns0:SingleRecord>
</ns0:AllRecords>
+4
source share
1 answer

Johns-305, Muenchian , , , . , . , XSLT .

, - - , , . , , . !

<?xml version="1.0" encoding="UTF-16"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                xmlns:msxsl="urn:schemas-microsoft-com:xslt"
                xmlns:var="http://schemas.microsoft.com/BizTalk/2003/var"
                exclude-result-prefixes="msxsl var s0"
                version="1.0"
                xmlns:s0="http://SmallGenericSchemaTest.Schemas/SourceSchema"
                xmlns:ns0="http://SmallGenericSchemaTest.Schemas/DestinationSchema">
    <xsl:output omit-xml-declaration="yes" method="xml" version="1.0" />

    <xsl:template match="/">
        <xsl:apply-templates select="/s0:TypedPolling" />
    </xsl:template>

    <xsl:template match="/s0:TypedPolling">
        <ns0:AllRecords>
            <xsl:for-each select="s0:TypedPollingResultSet0/s0:TypedPollingResultSet0">
                <ns0:SingleRecord>

                    <ns0:GroupA>
                        <xsl:if test="s0:SharedID">
                            <ns0:SharedID>
                                <xsl:value-of select="s0:SharedID/text()" />
                            </ns0:SharedID>
                        </xsl:if>

                        <xsl:if test="s0:MiscInfoA1">
                            <ns0:MiscInfoA1>
                                <xsl:value-of select="s0:MiscInfoA1/text()" />
                            </ns0:MiscInfoA1>
                        </xsl:if>

                        <xsl:if test="s0:MiscInfoA2">
                            <ns0:MiscInfoA2>
                                <xsl:value-of select="s0:MiscInfoA2/text()" />
                            </ns0:MiscInfoA2>
                        </xsl:if>
                    </ns0:GroupA>


                    <xsl:for-each select="/s0:TypedPolling/s0:TypedPollingResultSet1/s0:TypedPollingResultSet1[s0:SharedID = current()/s0:SharedID]">
                        <ns0:GroupB>
                            <xsl:if test="s0:MiscInfoB1">
                                <ns0:MiscInfoB1>
                                    <xsl:value-of select="s0:MiscInfoB1/text()" />
                                </ns0:MiscInfoB1>
                            </xsl:if>

                            <xsl:if test="s0:MiscInfoB2">
                                <ns0:MiscInfoB2>
                                    <xsl:value-of select="s0:MiscInfoB2/text()" />
                                </ns0:MiscInfoB2>
                            </xsl:if>

                            <ns0:SubGroupBAContainer>
                                <xsl:for-each select="/s0:TypedPolling/s0:TypedPollingResultSet2/s0:TypedPollingResultSet2[s0:SharedID = current()/s0:SharedID]">
                                    <ns0:SubGroupBA>
                                        <xsl:if test="s0:MiscInfoBA1">
                                            <ns0:MiscInfoBA1>
                                                <xsl:value-of select="s0:MiscInfoBA1/text()" />
                                            </ns0:MiscInfoBA1>
                                        </xsl:if>

                                        <xsl:if test="s0:MiscInfoBA2">
                                            <ns0:MiscInfoBA2>
                                                <xsl:value-of select="s0:MiscInfoBA2/text()" />
                                            </ns0:MiscInfoBA2>
                                        </xsl:if>
                                    </ns0:SubGroupBA>
                                </xsl:for-each>
                            </ns0:SubGroupBAContainer>

                            <ns0:SubGroupBBContainer>
                                <xsl:for-each select="/s0:TypedPolling/s0:TypedPollingResultSet3/s0:TypedPollingResultSet3[s0:SharedID = current()/s0:SharedID]">
                                    <ns0:SubGroupBB>
                                        <xsl:if test="s0:MiscInfoBB1">
                                            <ns0:MiscInfoBB1>
                                                <xsl:value-of select="s0:MiscInfoBB1/text()" />
                                            </ns0:MiscInfoBB1>
                                        </xsl:if>

                                        <xsl:if test="s0:MiscInfoBB2">
                                            <ns0:MiscInfoBB2>
                                                <xsl:value-of select="s0:MiscInfoBB2/text()" />
                                            </ns0:MiscInfoBB2>
                                        </xsl:if>
                                    </ns0:SubGroupBB>
                                </xsl:for-each>
                            </ns0:SubGroupBBContainer>
                        </ns0:GroupB>
                    </xsl:for-each>


                    <xsl:if test="/s0:TypedPolling/s0:TypedPollingResultSet4/s0:TypedPollingResultSet4[s0:SharedID = current()/s0:SharedID]">
                        <ns0:GroupCContainer>
                            <xsl:for-each select="/s0:TypedPolling/s0:TypedPollingResultSet4/s0:TypedPollingResultSet4[s0:SharedID = current()/s0:SharedID]">
                                <ns0:GroupC>
                                    <xsl:if test="s0:GroupCInstanceID">
                                        <ns0:GroupCInstanceID>
                                            <xsl:value-of select="s0:GroupCInstanceID/text()" />
                                        </ns0:GroupCInstanceID>
                                    </xsl:if>

                                    <xsl:if test="s0:MiscInfoC1">
                                        <ns0:MiscInfoC1>
                                            <xsl:value-of select="s0:MiscInfoC1/text()" />
                                        </ns0:MiscInfoC1>
                                    </xsl:if>

                                    <xsl:if test="s0:MiscInfoC2">
                                        <ns0:MiscInfoC2>
                                            <xsl:value-of select="s0:MiscInfoC2/text()" />
                                        </ns0:MiscInfoC2>
                                    </xsl:if>
                                </ns0:GroupC>
                            </xsl:for-each>
                        </ns0:GroupCContainer>
                    </xsl:if>


                    <xsl:if test="/s0:TypedPolling/s0:TypedPollingResultSet5/s0:TypedPollingResultSet5[s0:SharedID = current()/s0:SharedID]">
                        <ns0:GroupDContainer>
                            <xsl:for-each select="/s0:TypedPolling/s0:TypedPollingResultSet5/s0:TypedPollingResultSet5[s0:SharedID = current()/s0:SharedID]">
                                <ns0:GroupD>
                                    <xsl:if test="s0:GroupDInstanceID">
                                        <ns0:GroupDInstanceID>
                                            <xsl:value-of select="s0:GroupDInstanceID/text()" />
                                        </ns0:GroupDInstanceID>
                                    </xsl:if>

                                    <xsl:if test="s0:MiscInfoD1">
                                        <ns0:MiscInfoD1>
                                            <xsl:value-of select="s0:MiscInfoD1/text()" />
                                        </ns0:MiscInfoD1>
                                    </xsl:if>

                                    <xsl:if test="s0:MiscInfoD2">
                                        <ns0:MiscInfoD2>
                                            <xsl:value-of select="s0:MiscInfoD2/text()" />
                                        </ns0:MiscInfoD2>
                                    </xsl:if>

                                    <xsl:if test="/s0:TypedPolling/s0:TypedPollingResultSet6/s0:TypedPollingResultSet6[s0:SharedID = current()/s0:SharedID]
                                            and /s0:TypedPolling/s0:TypedPollingResultSet6/s0:TypedPollingResultSet6[s0:GroupDInstanceID = current()/s0:GroupDInstanceID]">
                                        <xsl:for-each select="/s0:TypedPolling/s0:TypedPollingResultSet6/s0:TypedPollingResultSet6[s0:SharedID = current()/s0:SharedID
                                                      and s0:GroupDInstanceID = current()/s0:GroupDInstanceID]">
                                            <ns0:SubGroupDA>
                                                <xsl:if test="s0:MiscInfoDA1">
                                                    <ns0:MiscInfoDA1>
                                                        <xsl:value-of select="s0:MiscInfoDA1/text()" />
                                                    </ns0:MiscInfoDA1>
                                                </xsl:if>

                                                <xsl:if test="s0:MiscInfoDA2">
                                                    <ns0:MiscInfoDA2>
                                                        <xsl:value-of select="s0:MiscInfoDA2/text()" />
                                                    </ns0:MiscInfoDA2>
                                                </xsl:if>
                                            </ns0:SubGroupDA>
                                        </xsl:for-each>
                                    </xsl:if>

                                    <xsl:if test="/s0:TypedPolling/s0:TypedPollingResultSet7/s0:TypedPollingResultSet7[s0:SharedID = current()/s0:SharedID]
                                            and /s0:TypedPolling/s0:TypedPollingResultSet7/s0:TypedPollingResultSet7[s0:GroupDInstanceID = current()/s0:GroupDInstanceID]">
                                        <ns0:SubGroupDBContainer>
                                            <xsl:for-each select="/s0:TypedPolling/s0:TypedPollingResultSet7/s0:TypedPollingResultSet7[s0:SharedID = current()/s0:SharedID
                                                          and s0:GroupDInstanceID = current()/s0:GroupDInstanceID]">
                                                <ns0:SubGroupDB>
                                                    <xsl:if test="s0:MiscInfoDB1">
                                                        <ns0:MiscInfoDB1>
                                                            <xsl:value-of select="s0:MiscInfoDB1/text()" />
                                                        </ns0:MiscInfoDB1>
                                                    </xsl:if>

                                                    <xsl:if test="s0:MiscInfoDB2">
                                                        <ns0:MiscInfoDB2>
                                                            <xsl:value-of select="s0:MiscInfoDB2/text()" />
                                                        </ns0:MiscInfoDB2>
                                                    </xsl:if>
                                                </ns0:SubGroupDB>
                                            </xsl:for-each>
                                        </ns0:SubGroupDBContainer>
                                    </xsl:if>
                                </ns0:GroupD>
                            </xsl:for-each>
                        </ns0:GroupDContainer>
                    </xsl:if>

                </ns0:SingleRecord>
            </xsl:for-each>
        </ns0:AllRecords>
    </xsl:template>
</xsl:stylesheet>
0

Source: https://habr.com/ru/post/1653486/


All Articles