CA API Management: Remove XML elements using XSLT

Document ID : KB000016621
Last Modified Date : 14/02/2018
Show Technical Document Details
Question:

How can you remove XML elements using XSLT?

Answer:

Given the below XML this XSLT can be used to remove particular elements from XML, in this example the "author" and "year" tags will be removed.

You can customize these values to meet your needs.

xml.png

XML

<bookstore>

<book category="API">

   <title lang="en">CA API Management</title>

   <author>John Doe</author>

   <year>2017</year>

   <price>30.00</price>

</book>

</bookstore>

 

 

xslt.png

XSLT

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:output indent="yes" omit-xml-declaration="yes"/>

 <xsl:template match="node()|@*">

  <xsl:copy>

   <xsl:apply-templates select="node()|@*"/>

  </xsl:copy>

 </xsl:template>

 <xsl:template match="author|year"/>

</xsl:stylesheet>