Re: [xsl] Selectively "delete" elements/attributes from the output

Subject: Re: [xsl] Selectively "delete" elements/attributes from the output
From: Kamal Bhatt <kbhatt@xxxxxxxxx>
Date: Thu, 01 Dec 2005 16:37:03 +1100
If you have this template:

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

it should pick up all templates that are not catered for by another template and copy them over.



avo@xxxxxxxxxxxxx wrote:

I'm doing XML to XML transformation (newbie when it comes to XML and XSLT)
Say I have an XML document like this

<element1 att1="a" att2="b">

I want to delete att1 and att2 from element1 so that output will look like this:

I could write a template that call <xsl:copy-of select=3D"..." to basically copy everything except the two attributes there. But this is just small examples, with more complex XML files, where I want to delete things here and there, this becomes unscalable (the problem applies to both attributes elements, and text, not just attributes)
Basically what I want to do is to have a template for each element/attribute that I want to "not copy" (delete), for ex:

<xsl:template match=3D"root/element1/@att1"/>
(doing nothing, essentially not copying the attribute over)

Since the built-in templates for everything else do not copy the element nodes over (only text nodes are output), I have to provide templates for the rest to copy them over (not sure how to do this effectively, either),
which is not very efficient.

So my question comes down to:
Can I provide rules for each of the thing I want to "delete", and then have one template to copy over everything else

Current Thread