I have been trying to understand muenchian grouping, but have some problems.
<xsl:key name="CollectionPerson" match="av:Detail[av:Content != '' or av:Code != '']" use="concat(@BlockName, '|', av:CollectionPerson)" />
<xsl:key name="SubCollection" match="av:Detail[av:Content != '' or av:Code != '']" use="concat(@BlockName, '|', av:CollectionPerson, '|', av:Collection_Id)" />
<xsl:key name="lv2" match="av:Detail[av:lv2]" use="concat(@BlockName, '|', av:lv2)" />
<xsl:key name="lv3" match="av:Detail[av:lv3]" use="concat(@BlockName, '|', av:lv3)" />
<xsl:key name="lv4" match="av:Detail[av:lv4]" use="concat(@BlockName, '|', av:lv4)" />
<xsl:key name="lv5" match="av:Detail[av:lv5]" use="concat(@BlockName, '|', av:lv5)" />
<xsl:key name="lv6" match="av:Detail[av:lv6]" use="concat(@BlockName, '|', av:lv6)" />
<xsl:key name="lv7" match="av:Detail[av:lv7]" use="concat(@BlockName, '|', av:lv7)" />
<xsl:key name="Collection_Id" match="av:Detail[@BlockName]" use="av:Collection_Id" />
<xsl:template name="create_block">
<xsl:param name="block_name"/>
<xsl:param name="element_link"/>
<xsl:param name="filter_link"/>
<xsl:param name="filter"/>
<xsl:param name="collected_block"/>
<xsl:variable name="elementf">
<xsl:value-of select="concat('lv', $filter_link)" />
</xsl:variable>
<xsl:variable name="element0">
<xsl:value-of select="concat('lv', $element_link)" />
</xsl:variable>
<xsl:variable name="element1">
<xsl:value-of select="concat('lv', $element_link + 1)" />
</xsl:variable>
<xsl:variable name="element2">
<xsl:value-of select="concat('lv', $element_link + 2)" />
</xsl:variable>
<xsl:variable name="element3">
<xsl:value-of select="concat('lv', $element_link + 3)" />
</xsl:variable>
<xsl:variable name="element4">
<xsl:value-of select="concat('lv', $element_link + 4)" />
</xsl:variable>
<xsl:variable name="element5">
<xsl:value-of select="concat('lv', $element_link + 5)" />
</xsl:variable>
<xsl:variable name="element6">
<xsl:value-of select="concat('lv', $element_link + 6)" />
</xsl:variable>
<xsl:for-each select="av:Data/av:Part/av:ReportPart1/av:Details/av:Detail[@BlockName=$block_name and *[name() = $elementf] = $filter and generate-id(.)=generate-id(key($element0, concat(@BlockName, '|', *[name() = $element0])))]">
<xsl:for-each select="key($element0, concat(@BlockName, '|', *[name() = $element0]))[@BlockName=$block_name and generate-id(.) = generate-id(key('CollectionPerson', concat(@BlockName, '|', av:CollectionPerson))[1])]">
<xsl:element name="av:{*[name() = $element2]}">
<xsl:for-each select="key('CollectionPerson', concat(@BlockName, '|', av:CollectionPerson))[generate-id(.) = generate-id(key('SubCollection', concat(@BlockName, '|', av:CollectionPerson, '|', av:Collection_Id)))] ">
<xsl:choose>
<xsl:when test="av:Collection_Id=''">
<xsl:call-template name="create_element">
<xsl:with-param name="element_name" select="*[name() = $element3]"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:if test="*[name() = $element6]">
<xsl:element name="av:{*[name() = $element3]}">
<xsl:element name="av:{*[name() = $element4]}">
<xsl:element name="av:{*[name() = $element5]}">
<xsl:for-each select="key('SubCollection',concat(@BlockName, '|', av:CollectionPerson, '|', av:Collection_Id))">
<xsl:sort select="av:Number"/>
<xsl:call-template name="create_element">
<xsl:with-param name="element_name" select="*[name() = $element6]"/>
</xsl:call-template>
</xsl:for-each>
</xsl:element>
</xsl:element>
</xsl:element>
</xsl:if>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
</xsl:element>
</xsl:for-each>
</xsl:for-each>
</xsl:template>
It skips all elements except first one, which do not have Collection_Id. In->>
<Detail BlockName="S">
<Number>1000</Number>
<Information>FirstName</Information>
<Content>John</Content>
<Code></Code>
<lv1>S</lv1>
<lv2>members</lv2>
<lv3>member</lv3>
<lv4>member_1</lv4>
<lv5>FirstName</lv5>
<CollectionPerson>2</CollectionPerson>
<Collection_Id></Collection_Id>
</Detail>
<Detail BlockName="S">
<Number>1100</Number>
<Information>SecondName</Information>
<Content>Smith</Content>
<Code></Code>
<lv1>S</lv1>
<lv2>members</lv2>
<lv3>member</lv3>
<lv4>member_1</lv4>
<lv5>SecondName</lv5>
<CollectionPerson>2</CollectionPerson>
<Collection_Id></Collection_Id>
</Detail>
<Detail BlockName="S">
<Number>1200</Number>
<Information>Value</Information>
<Content>100</Content>
<Code></Code>
<lv1>S</lv1>
<lv2>members</lv2>
<lv3>member</lv3>
<lv4>member_1</lv4>
<lv5>Acts</lv5>
<lv6>Act</lv6>
<lv7>Act_1</lv7>
<lv8>Value</lv8>
<CollectionPerson>2</CollectionPerson>
<Collection_Id>101</Collection_Id>
</Detail>
Result
<av:members>
<av:member>
<av:member_1>
<av:FirstName>John</av:FirstName>
<av:SecondName>Smith</av:SecondName> <!-- This element not appear -->
<av:Acts>
<av:Act>
<av:Act_1>
<av:Qty>10</av:Qty>
<av:Value>100</av:Value>
</av:Act_1>
</av:Act>
</av:Acts>
<av:member_1>
<av:member>
<av:members>
I'd appreciate any help as to where I'm going wrong. Thank you!
Use the following process to expand Muenchian grouping to multiple levels:
xsl-template
which matches the first keyfor-each
which matches the key for that levelReferences