XPath - xsl:copy-of select node, text without itself

J

jorgedelgadolopez

Hi,

I have been experimenting and searching for information on how to
retrieve the following using XPath.

I may have three types of XML:
<n>this is some text</n>
OR
<n>
<p>this is some text</p>
</n>
OR
<n>
<p>this is some text</p>
<p>some more text</p>
</n>
OR
<n>
this is some text
<p>some more text</p>
</n>

The result I need includes ALL of the children and/or text but NOT the
node element <n>.

Some of the tested xpath queries

<xsl:copy-of select="child::text()"/>
<xsl:copy-of select="child::*"/>
<xsl:copy-of select="self::*"/>
<xsl:copy-of select="self::node()"/>
<xsl:copy-of select="self::child"/>

and of course <xsl:copy-of select="."/> which returns <n>.

Any ideas?
/ jorge
 
R

Richard Tobin

The result I need includes ALL of the children and/or text but NOT the
node element <n>.

Some of the tested xpath queries

<xsl:copy-of select="child::text()"/>
<xsl:copy-of select="child::*"/>
<xsl:copy-of select="self::*"/>
<xsl:copy-of select="self::node()"/>
<xsl:copy-of select="self::child"/>

and of course <xsl:copy-of select="."/> which returns <n>.

You want all the children of the <n> element. So assuming the context
node is the <n>:

<xsl:copy-of select="node()"/>

-- Richard
 
D

David Carlisle

you want all (child) nodes so

<xsl:copy-of select="node()"/>

Of the ones you tried

<xsl:copy-of select="child::text()"/>
same as "text()" just selects child text nodes, not elements.

<xsl:copy-of select="child::*"/>
same as "*" just selects child elements, not text.

<xsl:copy-of select="self::*"/>
same as "." selects the current element.

<xsl:copy-of select="self::node()"/>
as above.

<xsl:copy-of select="self::child"/>
selects the empty set unless the current element has name "child" in
which case it would select the current element.


David
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,999
Messages
2,570,246
Members
46,841
Latest member
WilmerBelg

Latest Threads

Top