3 weeks ago
Hello
XSL gurus, will appreciate if someone can guide me for below issue in XSLT (3.0 version is ok).
Req is to replicate <RETAILLINEITEM/item> node and also modify some values based on some condition.
Condition/rule to replicate and modify is
TRANSTYPECODE = 1003 and RETAILTYPECODE = 2003
<SALESAMOUNT> field to be multiplied by -1.
Input payload:
<ns1:root xmlns:ns1="urn:sap-com:document:sap:rfc:functions">
<IT_TRANSACTION>
<item>
<RETAILSTOREID>01962</RETAILSTOREID>
<TRANSTYPECODE>1003</TRANSTYPECODE>
<RETAILLINEITEM>
<item>
<RETAILNUMBER>0</RETAILNUMBER>
<RETAILTYPECODE>2003</RETAILTYPECODE>
<ITEMIDQUALIFIER>1</ITEMIDQUALIFIER>
<RETAILQUANTITY>1</RETAILQUANTITY>
<SALESUOM>PCE</SALESUOM>
<SALESAMOUNT>4.44</SALESAMOUNT>
</item>
</RETAILLINEITEM>
<TAX>
<item>
<TAXNUMBER>1</TAXNUMBER>
<TAXTYPECODE>ZST1</TAXTYPECODE>
<TAXAMOUNT>0.00</TAXAMOUNT>
</item>
</TAX>
</item>
</IT_TRANSACTION>
</ns1:root>
<RETAILLINEITEM/item> should be copied and also amount values to be multiplied by -1
Output payload:
<ns1:root xmlns:ns1="urn:sap-com:document:sap:rfc:functions">
<IT_TRANSACTION>
<item>
<RETAILSTOREID>01962</RETAILSTOREID>
<TRANSTYPECODE>1003</TRANSTYPECODE>
<RETAILLINEITEM>
<item>
<RETAILNUMBER>0</RETAILNUMBER>
<RETAILTYPECODE>2003</RETAILTYPECODE>
<ITEMIDQUALIFIER>1</ITEMIDQUALIFIER>
<RETAILQUANTITY>1</RETAILQUANTITY>
<SALESUOM>PCE</SALESUOM>
<SALESAMOUNT>4.44</SALESAMOUNT>
</item>
<!-- Below item node should be copied from above and <salesamount> should be multiplied by -1 -->
<item>
<RETAILNUMBER>0</RETAILNUMBER>
<RETAILTYPECODE>2003</RETAILTYPECODE>
<ITEMIDQUALIFIER>1</ITEMIDQUALIFIER>
<RETAILQUANTITY>1</RETAILQUANTITY>
<SALESUOM>PCE</SALESUOM>
<SALESAMOUNT>-4.44</SALESAMOUNT> <!-- Negative amt -->
</item>
</RETAILLINEITEM>
<TAX>
<item>
<TAXNUMBER>1</TAXNUMBER>
<TAXTYPECODE>ZST1</TAXTYPECODE>
<TAXAMOUNT>0.00</TAXAMOUNT>
</item>
</TAX>
</item>
</IT_TRANSACTION>
</ns1:root>
How about
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" omit-xml-declaration="yes" indent="yes"/>
<xsl:template match="@* | node()" mode="#all">
<xsl:copy>
<xsl:apply-templates select="@* | node()" mode="#current"/>
</xsl:copy>
</xsl:template>
<xsl:template match="RETAILLINEITEM/item">
<xsl:copy-of select="."/>
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="RETAILLINEITEM/item/SALESAMOUNT" >
<xsl:copy>
<xsl:value-of select=". * -1"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
Regards,
Jamie
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
66 | |
10 | |
10 | |
10 | |
10 | |
8 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.