954,568 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Getting rid of elements that have attributes

Another total Nuby collection.

I have an xml file from which I wish to eliminate all elements that have any attributes at all. All I really need to do is eliminate the contents of the attribute. How do I do this?

My plan is to start with

Of course the XPATH equivalent to "Contains an attribute" is unknown to me.

All help appreciated

Achava

achava
Light Poster
27 posts since Oct 2010
Reputation Points: 10
Solved Threads: 0
 

It's an Identity Template with a match on ANY element that has an attribute. ' match="*[@*]" '

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

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

	<xsl:template match="*[@*]" />
</xsl:stylesheet>
iceandrews
Junior Poster
185 posts since May 2010
Reputation Points: 10
Solved Threads: 30
 

Thank you for your answer.

achava
Light Poster
27 posts since Oct 2010
Reputation Points: 10
Solved Threads: 0
 

You might want to also remove all the resulting whitespace by adding

<xsl:strip-space elements="*"/>

to the stylesheet provided by iceandrews.

fpmurphy
Junior Poster
147 posts since Oct 2008
Reputation Points: 22
Solved Threads: 11
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You