XSLT 1.0: IDOC to AdsML transformation

I need to transform SAP IDOC xml into AdsML format.But the abstract question is: how to transform xml1 into xml2?xml1:\[code\]<E1BPBUSISM008_ITEM_OUT> <ITEM_NUMBER>010</ITEM_NUMBER></E1BPBUSISM008_ITEM_OUT><E1BPBUSISM008_ITEM_OUT> <ITEM_NUMBER>020</ITEM_NUMBER> </E1BPBUSISM008_ITEM_OUT><E1BPBUSISM008_AD_SPEC_AD_OU> <ITEM_NUMBER>010</ITEM_NUMBER> <PLANNED_WIDTH>1.851</PLANNED_WIDTH> <PLANNED_HEIGHT>0.000</PLANNED_HEIGHT></E1BPBUSISM008_AD_SPEC_AD_OU><E1BPBUSISM008_AD_SPEC_AD_OU> <ITEM_NUMBER>020</ITEM_NUMBER> <PLANNED_WIDTH>2.37</PLANNED_WIDTH> <PLANNED_HEIGHT>0.000</PLANNED_HEIGHT></E1BPBUSISM008_AD_SPEC_AD_OU>\[/code\]into xml2:\[code\]<Ad> <ad-number>010<ad-number> <width>1.851</width> <height>0.000</height></Ad><Ad> <ad-number>020<ad-number> <width>2.37</width> <height>0.000</height></Ad>\[/code\]What I have tried here is Muench method, but even if it is the correct solution for this case, not sure how to complete it, because it returns wrong 'width' and 'heigth' (the same for all Ad elements):\[code\]<xsl:key name="adnumbers" match="IE1BPBUSISM008_ITEM_OUT" use="ITEM_NUMBER"/>....<xsl:for-each select="E1BPBUSISM008_ITEM_OUT[generate-id(.)=generate-id(key('adnumbers',ITEM_NUMBER)[1])]"><xsl:sort select="ITEM_NUMBER"/><Ad><ad-number> <xsl:value-of select="ITEM_NUMBER/text()"/></ad-number><width><xsl:value-of select="E1BPBUSISM008_AD_SPEC_AD_OU/PLANNED_WIDTH"/></width><height><xsl:value-of select="E1BPBUSISM008_AD_SPEC_AD_OU/PLANNED_HEIGHT"/></height>\[/code\]outputs:\[code\]<Ad> <number>010</ad-number> <width>1.851</width> <heigth>0.000</heigth></Ad><Ad> <number>020</ad-number> <width>1.851</width> <heigth>0.000</heigth></Ad>\[/code\]
 
Back
Top