I'm trying to convert an sap iDoc to another xml file with a BizTalk map written in xslt. The problem is I need to group nodes based on a value that we can find in a specific subnode.
Muenchian grouping (I use XSLT 1.0) seems to be the solution but I can't find out how to make it works as I need to group on subnode value.
<Receive>
<idocData>
<E2EDL20003GRP>
<E2EDL2003>
<ParentValue>PV</ParentValue>
</E2EDL2003>
...
<E2EDL24007GRP>
<E2EDL24007>
<ChildValue>CHV1</ChildValue>
</E2EDL24007>
<E2EDL43000>
<QUALF>C</QUALF>
<BELNR>0000045690</BELNR>
</E2EDL43000>
...
</E2EDL24007GRP>
<E2EDL24007GRP>
<E2EDL24007>
<ChildValue>CHV2</ChildValue>
</E2EDL24007>
<E2EDL43000>
<QUALF>C</QUALF>
<BELNR>0000045690</BELNR>
</E2EDL43000>
...
</E2EDL24007GRP>
<E2EDL24007GRP>
<E2EDL24007>
<ChildValue>CHV3</ChildValue>
</E2EDL24007>
<E2EDL43000>
<QUALF>C</QUALF>
<BELNR>0000045691</BELNR>
</E2EDL43000>
...
</E2EDL24007GRP>
</E2EDL20003GRP>
</idocData>
</Receive>
After applying the XSLT transformation, what I am looking for is :
<ns0:Root>
<RecordA>
<ID>PV</ID>
<RecordB>
<ID>0000045690</ID>
<RecordC>
<Value>CHV1</Value>
</RecordC>
<RecordC>
<Value>CHV2</Value>
</RecordC>
</RecordB>
<RecordB>
<ID>0000045691</ID>
<RecordC>
<Value>CHV3</Value>
</RecordC>
</RecordB>
</RecordA>
</ns0:Root>
As you can see, I need to group E2EDL24007GRP by E2EDL43000[QUALF='C']/BELNR
.
I tried the following muenchian grouping :
<xsl:key name="command" match="s0:E2EDL24007GRP" use="s0:E2EDL43000[s0:QUALF='C']/s0:BELNR" />
<xsl:template match="/">
<xsl:apply-templates select="/s1:Receive" />
</xsl:template>
<xsl:template match="/s1:Receive/s1:idocData">
<xsl:for-each select="s0:E2EDL20003GRP">
<ns0:Root>
<!-- Record A -->
<RecordA>
<ID>
<xsl:value-of select="s0:E2EDL2003/s0:ParentValue" />
</ID>
<xsl:apply-templates select="s0:E2EDL24007GRP[generate-id()=generate-id(key('command',s0:E2EDL43000[s0:QUALF='C']/s0:BELNR)[1])]"/>
</RecordA>
</ns0:Root>
</xsl:for-each>
</xsl:template>
<xsl:template match="E2EDL24007GRP">
...
</xsl:template>
But it didn't work at all, any idea ?
The following stylesheet:
XSLT 1.0
applied to your input example, will produce:
Result
Note: