You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by Hans-Guenter Stein <Ha...@siteos.de> on 2000/07/13 16:57:24 UTC

how to copy...

How to make a deep copy of a node without copying the node itself (but
copying its value)?

i.e.:

input:
<mynode>This is <i>very</i>important</mynode>

should result in output:
This is <i>very</i>important



Re: how to copy...

Posted by Andrius Sabanas <an...@taide.lt>.
Jeremy Quinn wrote:

> something like this?
> 
> <xsl:template match="mynode">
>         <xsl:for-each select="*">
>                 <xsl:apply-templates/>
>         </xsl:for-each>
> </xsl:template>
> 
> with this at the end of your stylesheet ....
> 
> <xsl:template match="*|@*|text()">
>         <xsl:copy>
>                 <xsl:apply-templates select="*|@*|text()"/>
>         </xsl:copy>
> </xsl:template>


This also works, but with one exception - if you use <xsl:import>, 
all imported templates are overriden by this last one.


-- 
Andrius Sabanas
mailto:andsh@taide.lt
http://metclub.node.lt

Re: how to copy...

Posted by Jeremy Quinn <je...@media.demon.co.uk>.
At 16:57 +0200 13/07/00, Hans-Guenter Stein wrote:
>How to make a deep copy of a node without copying the node itself (but
>copying its value)?
>
>i.e.:
>
>input:
><mynode>This is <i>very</i>important</mynode>
>
>should result in output:
>This is <i>very</i>important

something like this?

<xsl:template match="mynode">
	<xsl:for-each select="*">
		<xsl:apply-templates/>
	</xsl:for-each>
</xsl:template>

with this at the end of your stylesheet ....

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


hope this helps

regards Jeremy
-- 
   ___________________________________________________________________

   Jeremy Quinn                                           Karma Divers
                                                       webSpace Design
                                            HyperMedia Research Centre

   <ma...@mac.com>     		 <http://www.media.demon.co.uk>
    <phone:+44.[0].20.7737.6831>        <pa...@sms.genie.co.uk>

Re: how to copy...

Posted by Andrius Sabanas <an...@taide.lt>.
Hans-Guenter Stein wrote:
> 
> How to make a deep copy of a node without copying the node itself (but
> copying its value)?
> 
> i.e.:
> 
> input:
> <mynode>This is <i>very</i>important</mynode>
> 
> should result in output:
> This is <i>very</i>important


Hi,

try something like this:

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

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

Maybe there is a more effective way, I don't know :-)


-- 
Andrius Sabanas
mailto:andsh@taide.lt
http://metclub.node.lt