Welcome to WebmasterWorld Guest from 54.167.213.22

Forum Moderators: httpwebwitch

Message Too Old, No Replies

Basic help on copying elements using XSL

     
12:22 pm on Jul 8, 2011 (gmt 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">
<xsl:copy>
<xsl:apply-templates/>
</xsl:copy>
<div class="activity">
<xsl:apply-templates />
</div>
</xsl:template>

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

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



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 Jul 8, 2011 (gmt 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!
 

Featured Threads

Hot Threads This Week

Hot Threads This Month