2024 Sep 22 12:49 PM - edited 2024 Sep 22 12:50 PM
Hi Experts,
I have a XML payload from which I need to remove only the XML tag and the values should pass to the parent tag. Sample payload mentioned below -
I tried few groovy functions mentioned on the community but that is replacing the entire <AdditionalComments/> tag to blank which is not expected.
Please help me if we can take this with groovy or I need to go with XSLT?
Thanks.
Best Regards,
Nidhi Srivastava
Hi Nidhi,
Below XSLT will achieve the result you want
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="3.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<!-- Identity transform using xsl:mode -->
<xsl:mode on-no-match="shallow-copy"/>
<!-- Special handling for AdditionalComments -->
<xsl:template match="AdditionalComments">
<xsl:copy>
<xsl:value-of select="div"/>
</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.
Hi Nagesh,
Thanks for your help. This code works fine, but it fails when there is assigned to field sent.
<AssignedTo>ABC XYZ <ABC.XYZ@gmail.com></AssignedTo>
Hello Nidhi,
The error occurs because the email address in the AssignedTo field contains the '@' character, which is not valid in XML content outside of attributes.
Assuming you will get this '@' only in the field - "AssignedTo" we can update the XSLT to ignore that as below
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="3.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<!-- Identity transform using xsl:mode -->
<xsl:mode on-no-match="shallow-copy"/>
<!-- Special handling for AdditionalComments -->
<xsl:template match="AdditionalComments">
<xsl:copy>
<xsl:value-of select="div"/>
</xsl:copy>
</xsl:template>
<!-- Explicitly copy AssignedTo without changes -->
<xsl:template match="AssignedTo">
<xsl:copy-of select="."/>
</xsl:template>
</xsl:stylesheet>
User | Count |
---|---|
68 | |
10 | |
10 | |
7 | |
6 | |
6 | |
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.