[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Remove a particluar Attribute from all the node

Subject: Re: Remove a particluar Attribute from all the node
From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx>
Date: Thu, 22 Apr 2004 09:56:40 +0100
xsl remove attribute
Hi Animesh,

> I want to write an XSL which will remove the particular attribute
> from all the node in the DOM tree.

Since you want the tree to basically stay the same, the core of your
transformation should be the identity template:

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

On its own, this creates a deep copy of the source document. If you
want to exclude a particular attribute, you just need to add a
template that matches that attribute and does nothing with it (doesn't
copy it). So, to exclude the fr_elementid attribute, you should couple
the identity template above with the template:

<xsl:template match="@fr_elementid" />

By the way, in your XSLT you had:

> <xsl:template match="@*">
> 	 <xsl:choose>
> 	 <xsl:when test="name()='fr_elementid'">	
> 	 </xsl:when>
> 	<xsl:otherwise>
> 		<xsl:copy>
> 			<xsl:apply-templates select="."/>
> 		</xsl:copy>	
> 	</xsl:otherwise>
> 	</xsl:choose>
> </xsl:template>

When this matches an attribute other than the fr_elementid attribute,
it copies that attribute and then applies templates to that attribute.
The template that gets used on the attribute is this one, so the
attribute gets copied again and templates applied to it. And so it
goes on and on in an infinite loop. When you copy an attribute, you
get its value as well, so what you actually wanted was:

  <xsl:otherwise>
    <xsl:copy />
  </xsl:otherwise>

or, if you prefer:

  <xsl:otherwise>
    <xsl:copy-of select="." />
  </xsl:otherwise>

Cheers,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.