Update: Cascade deletions with XSLT

Within the first 24 hours of posting Cascade deletions with XSLT,  David Carlisle came up with improved XSLT 2.0 solution (below). David’s solution main improvement is not so much in being just 37 lines long (3 lines down from the 40-line solution I originally posted) but in defining with an <xsl:key> all nodes to be deleted. So, the intersect operator from my solution is not used in David’s, which should translate in better speed. Thank you, David.

 

 Cascade deletions — XSLT 2 (David Carlisle)

 

<xsl:stylesheet version="2.0
 xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
 <xsl:output omit-xml-declaration="yes" indent="yes"/>
 <xsl:strip-space elements="*"/> 

 <xsl:key name="x" match="class
         use="@name"/> 

<xsl:key name="x" match="beast
         use="@class"/> 

<xsl:key name="beastbytype" match="beast
         use="@type"/> 

<xsl:key name="x" match="breed
 use="key(‘beastbytype’,@type)/@class"/> 

<xsl:key name="breadbyname" match="breed
         use="@name"/> 

<xsl:key name="x" match="pet" use=
    "key(‘beastbytype’,
          key(‘breadbyname’,@breed)
                          /@type
          )
           /@class"/> 

<xsl:template match="*">
 <xsl:copy>
   <xsl:copy-of select="@*"/>
   <xsl:apply-templates/>
 </xsl:copy>
</xsl:template> 

<xsl:template match="key(‘x’,’Aves’)"/> 

</xsl:stylesheet>

About these ads
This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s