Welcome to WebmasterWorld Guest from

Forum Moderators: httpwebwitch

Message Too Old, No Replies

Basic help on copying elements using XSL

12:22 pm on Jul 8, 2011 (gmt 0)

New User

joined:July 8, 2011
posts: 2
votes: 0

In my XSL, I'm trying to copy a complex element, **then** apply a template to it. Currently the templates are only being applied to the children of the copied element.

Thanks for your help... I appreciate this is basic stuff.

This is what I'm trying, which is clearly wrong.

<xsl:template match="activity">
<div class="activity">
<xsl:apply-templates />

1:35 pm on July 8, 2011 (gmt 0)

Moderator This Forum from CA 

WebmasterWorld Administrator httpwebwitch is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Aug 29, 2003
votes: 0

Welcome to WebmasterWorld!

<xsl:copy> is a "shallow" copy, and (according to the manual) only copies the current node. <xsl:copy-of> is a "deep" copy, which does a recursive copy of all the node's children.

Have you tried matching the parent of "activity" instead?
2:08 pm on July 8, 2011 (gmt 0)

New User

joined:July 8, 2011
posts: 2
votes: 0

I can use <xsl:copy-of select="activity" /> in the matched parent, and this copies the nodes from the XML. How do I then apply the <xsl:template match="activity"> to this copied output?

I seem to be able to use <xsl:apply-templates /> only when using <xsl:copy>, not copy-of.

I'm so confused!