tags:

views:

85

answers:

3

My need: I want to deep copy all the childs of a single selected node without actually copying it. Example: from

<father><son i="1" /><son i="2" /><son i="0"><lastNode /></son></father>

i wish to extract

<son i="1" /><son i="2" /><son i="0"><lastNode /></son>

I know that i can do this with a cycle for-each and then a xsl:copy-of. I am wondering if there is a simpler expression to achieve the same result. Some idea?

Follow-up. My question missed a couple of points. I should had said that all the childs means "all the possible childs", including textnodes; another verification that a better question already contains the answer. Second, what I have learned from you - the community - is that I was enough dumb to try to solve by XSL what in facts was more a XPATH issue. Thanks to all of you for this insight

Cheers.

A: 

Use e.g. <xsl:copy-of select="father/son"/>

jelovirt
My fault: my example was misleading. Your solution works only if alle the childs are <son />. If you have <father><aDifferentSon /><son i="1" /><son i="2" /><son i="0"><lastNode /></son></father> this do not works anymore
Daniel
+3  A: 

Try select all children..

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"&gt;
<xsl:template match="/">
    <xsl:copy-of select="father/*"/>
</xsl:template>
</xsl:stylesheet>

E.G. Given input

<father><son i="1" /><son i="2" /><niceSon /><son i="0"><lastNode /></son></father>

It outputs

<son i="1" /><son i="2" /><niceSon /><son i="0"><lastNode /></son>
codemeit
+2  A: 
<xsl:copy-of select="father/node()" />
mikesub
this will match all nodes other than an attribute node.
mikesub
Your comment was useful. I have overlooked at first the difference between the solution proposed by you and the solution proposed by codemeit; but, in facts, your solution is the proper one when you need to copy textnodes. Example: if i need to tranform to html something like: <content>Bla bla bla <b>I said bla!</b> etc. etc. </content> then <xsl:copy-of select="content/node()" /> does what I really meant while the oter solution keep only <b>I said bla!</b>. The good news is that we have ever something to learn ...
Daniel