Final response should be xml response received from called target endpoint plus an additional xml tag indicator with fixed boolean value.Please suggest
How to add an additional xml node into xml response received from target endpoint
Solved! Go to Solution.
@paridhi agarwal, you can use a generic xsl transformation that just adds your new element to the root element (whatever that may be) and copies all its children: (XSLT adapted from https://stackoverflow.com/questions/25957167/xslt-to-add-new-elements-to-the-root-element-of-an-xml)
<?xml version="1.0"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/> <!-- match the root element of unknown name --> <xsl:template match="/*"> <xsl:copy> <!-- copy its children --> <xsl:copy-of select="@*|node()"/> <!-- add a new element at the end --> <name>abc</name> </xsl:copy> </xsl:template> </xsl:stylesheet>
Thanks much for the response Anil. I tried implementing it , but now the challenge is xml structure returned by target url is not always fixed and known. So I will not be having any xsl stylesheet to refer to. I just know watever be the response , we have to add " <name>abc</name> " tag in the end and send back to client. Please suggest .
@paridhi agarwal, you can use a generic xsl transformation that just adds your new element to the root element (whatever that may be) and copies all its children: (XSLT adapted from https://stackoverflow.com/questions/25957167/xslt-to-add-new-elements-to-the-root-element-of-an-xml)
<?xml version="1.0"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/> <!-- match the root element of unknown name --> <xsl:template match="/*"> <xsl:copy> <!-- copy its children --> <xsl:copy-of select="@*|node()"/> <!-- add a new element at the end --> <name>abc</name> </xsl:copy> </xsl:template> </xsl:stylesheet>