<xsl:output indent="yes"/>
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="root">
<xsl:copy>
<xsl:for-each-group select="RemittanceInformation" group-by="IndividualRemittance/ExchangeAssignedPolicyID">
<xsl:copy>
<xsl:variable name="pos" select="position()"/>
<xsl:apply-templates select="EntityAssignedNumber, IndividualRemmittance, current-group()/RemittanceDetail">
<xsl:with-param name="pos" select="$pos"/>
</xsl:apply-templates>
</xsl:copy>
</xsl:for-each-group>
</xsl:copy>
</xsl:template>
<xsl:template match="EntityAssignedNumber">
<xsl:param name="pos"/>
<xsl:copy>
<xsl:value-of select="/root/RemittanceInformation[1]/EntityAssignedNumber + $pos - 1"/>
</xsl:copy>
</xsl:template>
I got this code from the super helpful martin-honnen on S/O, but one thing it doesn't do is, when a node of type RemittanceInformation doesn't have an IndividualRemmittance, it doesn't copy it at all.
What I would like is when there is an IndividualRemmittance, to group them together so there are no duplicates (The code does that already), but when it runs into a RemittanceInformation without an IndividualRemmittance, it should just copy it across normally.
What do I need to alter to make that happen?