我需要将 SAP IDOC xml 转换为 AdsML 格式。但抽象的问题是:如何将 xml1 转换为 xml2?
xml1:
<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>
进入xml2:
<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>
我在这里尝试的是 Muench 方法,但即使它是这种情况下的正确解决方案,也不知道如何完成它,因为它返回错误的“宽度”和“高度”(所有广告元素都相同):
<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>
输出:
<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>