on 01-24-2023 3:45 AM
Hi Experts,
I have the below input XML from the Source system. But they are sending with a namespace, so I would like to remove it.
I know that I can use the filter/groovy step before XSLT mapping to remove the namespace. But, I would like to use XSLT to remove the namespace to avoid unnecessary message steps.
Source XML:
<GoodsReceiptHeader xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.abc.com/defghij/2011/11">
<TimeOfDelivery>2023-01-06T10:19:00</TimeOfDelivery>
<ReceiptId>543221</ReceiptId>
<GoodsReceiptUnits>
<GoodsReceiptUnit>
<Barcode>12334567890</Barcode>
<Status>A</Status>
</GoodsReceiptUnit>
<GoodsReceiptUnit>
<Barcode>0987654321</Barcode>
<Status>A</Status>
</GoodsReceiptUnit>
</GoodsReceiptUnits>
</GoodsReceiptHeader><br>
XSLT:
<strong><?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:cpi="http://sap.com/it/" exclude-result-prefixes="cpi" version="3.0">
<xsl:param name="RCVPRN"/>
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:mode on-no-match="shallow-copy"/>
<xsl:template match="/GoodsReceiptHeader">
<ZWPUWBW01>
<IDOC>
*
*
*
*
*
</IDOC>
</ZWPUWBW01>
</xsl:template>
</xsl:stylesheet></strong><b><br></b>
Any leads will be really helpful.
Regards,
Pavan
Hello Pavan.
You can remove the namespaces you define in your stylesheet by setting exclude-result-prefixes="#all". The namespaces from your source will not be in your target xml, as you do not copy any nodes that use them. To select a value from your source you have to adjust your xslt to use the corresponding namespace from your source file.
Stylesheet:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:cpi="http://sap.com/it/" xmlns:n1="http://schemas.abc.com/defghij/2011/11" exclude-result-prefixes="#all" version="3.0">
<xsl:param name="RCVPRN"/>
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:mode on-no-match="shallow-copy"/>
<xsl:template match="/n1:GoodsReceiptHeader">
<ZWPUWBW01>
<IDOC>
<xyz>
<xsl:value-of select="n1:ReceiptId"/>
</xyz>
</IDOC>
</ZWPUWBW01>
</xsl:template>
</xsl:stylesheet>
Result:
<?xml version="1.0" encoding="UTF-8"?>
<ZWPUWBW01>
<IDOC>
<xyz>543221</xyz>
</IDOC>
</ZWPUWBW01>
Alertativly you can use a second XSLT script prior to the first where you delete all namespaces from the source file. In this case you do not need to adhere to the namespace in your xslt. Example from stackoverflow. But I would suggest the first methode as you only need one xslt script.Best regardsRobert
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello babruvahana,
you mean, to select a node without declaring/ knowing the namespace of it? If yes, you can use the local-name() function.
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" exclude-result-prefixes="#all" version="3.0">
<xsl:param name="RCVPRN"/>
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:mode on-no-match="shallow-copy"/>
<xsl:template match="/">
<ZWPUWBW01>
<IDOC>
<xyz>
<xsl:value-of select="//*[local-name()='GoodsReceiptHeader']/*[local-name()='ReceiptId']"/>
</xyz>
</IDOC>
</ZWPUWBW01>
</xsl:template>
</xsl:stylesheet>
Best Regards
Robert
User | Count |
---|---|
93 | |
10 | |
10 | |
9 | |
9 | |
7 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.