Deleting Content

If your rule for a node does nothing—that is, it’s empty—the content of the matched node is not copied to the output document. In this way, you can selectively remove content from the source document when you write the output document.

Imagine that you wanted to remove all data about the various planets in planets.xml except for their names and masses. Here’s a stylesheet that does the trick:

Listing 3.7. Deleting Content
 <?xml version="1.0"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:strip-space elements="*"/> <xsl:output method="xml" indent="yes"/> <xsl:template match="/"> <xsl:apply-templates/> </xsl:template> <xsl:template match="PLANETS"> <xsl:apply-templates/> </xsl:template> ...

Get Inside XSLT now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.