I have this XML node:
<partyIdentification>
<id>123</id>
<schemeId>1111</schemeId>
<!--GlobalIDs start from here-->
<id>1234567</id>
<schemeId>0011</schemeId>
<id>7654321</id>
<schemeId>0022</schemeId>
<id>98765432</id>
<schemeId>0033</schemeId>
<id>13680123</id>
<schemeId>0044</schemeId>
</partyIdentification>
I need to loop through these and recreate the structure like this:
<partyIdentification>
<ID sid="1111">123</id>
<GlobalID sid="0011">1234567</GlobalID>
<GlobalID sid="0022">7654321</GlobalID>
<GlobalID sid="0033">98765432</GlobalID>
<GlobalID sid="0044">13680123</GlobalID>
</partyIdentification>
Please note: id and schemeId are linked to each other. So, if there is a schemeID after id, then those are grouped together, as you can see in expected result. So, anything which comes before the comment: "GlobalIDs start from here" should be added to the field <ID and in attribute sid, there can be multiple before this comment. And, whatever comes after the comment "GlobalIDs start from here" should go in <GlobalID and in sid attribute.
I tried many things, for example exsl:node-set and also preceeding and following sibling:
<xsl:template match="partyIdentification/id[following-sibling::comment()[1]]">
<xsl:variable name="IDs">
<xsl:copy-of select="."/>
</xsl:variable>
<xsl:variable name="IDsRestructuring">
<xsl:for-each select="$IDs/id">
<id sid="{following-sibling::schemeId[1]}"><xsl:value-of select="normalize-space(.)"/></id>
</xsl:for-each>
</xsl:variable>
<xsl:for-each select="exsl:node-set($IDsRestructuring)/id">
<ID schemeID="{@sid}"><xsl:value-of select="."/></ID>
</xsl:for-each>
</xsl:template>
Can someone please help?