Re: [xsl] Add attribute to all node

Subject: Re: [xsl] Add attribute to all node
From: David Carlisle <davidc@xxxxxxxxx>
Date: Thu, 29 Apr 2004 14:23:50 +0100
> It adds the attribute only in root element.


Strange I would have expected it to work, but it is rather a strange
stylesheet.

<xsl:template match="//*">

That matches exactly the same elements as

<xsl:template match="*">

The only function of // is to change the default priority.
That means this template has higher priority for * than 

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

which is good, otherwise there would be a recoverable error condition.
Since this second template will never fire for elements, you needn't
have * in the match and you needn't apply xsl:templates to teh chidren
as there are no children.

So all you need is something like

<xsl:stylesheet...
<xsl:template match="*">
	<xsl:copy>
		<xsl:copy-of select="@*"/>
		<xsl:attribute name="test1">Name</xsl:attribute>
		<xsl:apply-templates/>
	</xsl:copy>
</xsl:template>

</xsl:stylesheet>


Which processor are you using? perhaps it is not setting the priority
for //* correctly and treating it like * in which case I would have
expected that your second template was always used, and teh attribute
was never added. (That would still be a bug)

David

________________________________________________________________________
This e-mail has been scanned for all viruses by Star Internet. The
service is powered by MessageLabs. For more information on a proactive
anti-virus service working around the clock, around the globe, visit:
http://www.star.net.uk
________________________________________________________________________

Current Thread