on 2024 Sep 09 3:18 PM
Hello
Can someone please help in identifying the below issue in my xslt ? Req is to delete complete xml node based on one child node field.
XML input:
<?xml version="1.0" encoding="UTF-8"?>
<ns1:root xmlns:ns1="urn:sap-com:document:sap:rfc:functions">
<IT_TRANSACTION>
<item>
<RETAILSTOREID>0000002620</RETAILSTOREID>
<TRANSTYPECODE>1001</TRANSTYPECODE>
<TRANSNUMBER>5</TRANSNUMBER>
<RETAILLINEITEM>
<item>
<ITEMIDQUALIFIER>1</ITEMIDQUALIFIER>
<ITEMID>4004845460629</ITEMID>
</item>
</RETAILLINEITEM>
<TAX>
<item>
<TAXTYPECODE>ZCO1</TAXTYPECODE>
<TAXAMOUNT>1.00</TAXAMOUNT>
</item>
</TAX>
</item>
<item>
<RETAILSTOREID>0000002621</RETAILSTOREID>
<TRANSTYPECODE/>
<TRANSNUMBER>6</TRANSNUMBER>
<RETAILLINEITEM>
<item>
<ITEMIDQUALIFIER>1</ITEMIDQUALIFIER>
<ITEMID>4004845460629</ITEMID>
</item>
</RETAILLINEITEM>
<TAX>
<item>
<TAXTYPECODE>ZCO1</TAXTYPECODE>
<TAXAMOUNT>1.00</TAXAMOUNT>
</item>
</TAX>
</item>
</IT_TRANSACTION>
</ns1:root>
XML output: 2nd item node should be completely deleted/rejected as TRANSTYPECODE is blank.
<?xml version="1.0" encoding="UTF-8"?>
<ns1:root xmlns:ns1="urn:sap-com:document:sap:rfc:functions">
<IT_TRANSACTION>
<item>
<RETAILSTOREID>0000002620</RETAILSTOREID>
<TRANSTYPECODE>1001</TRANSTYPECODE>
<TRANSNUMBER>5</TRANSNUMBER>
<RETAILLINEITEM>
<item>
<ITEMIDQUALIFIER>1</ITEMIDQUALIFIER>
<ITEMID>4004845460629</ITEMID>
</item>
</RETAILLINEITEM>
<TAX>
<item>
<TAXTYPECODE>ZCO1</TAXTYPECODE>
<TAXAMOUNT>1.00</TAXAMOUNT>
</item>
</TAX>
</item>
</IT_TRANSACTION>
</ns1:root>
XSL code:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format"
xmlns:ns1="urn:sap-com:document:sap:rfc:functions">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:template match="@* | node()">
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
</xsl:template>
<!-- Match and output only the segments meeting the specified condition -->
<xsl:template match="ns1:item[TRANSTYPECODE = '']">
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
</xsl:template>
<!-- Suppress output of all other segments -->
<xsl:template match="//ns1:item"/>
</xsl:stylesheet>
Thanks Ryan - that is what I intended in my code but its copying everything - I also tried with some values like 1001 /1002 and code should just copy let's say 1001 and ignore 1002.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
70 | |
11 | |
11 | |
10 | |
9 | |
9 | |
7 | |
6 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.