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>
Request clarification before answering.
Thanks, it works now.
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes"/>
<xsl:template match="item[TRANSTYPECODE = '']"/>
<xsl:template match="@* | node()">
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
84 | |
29 | |
9 | |
9 | |
8 | |
8 | |
7 | |
6 | |
6 | |
6 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.