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

Discussion in 'XML' started by jorgedelgadolopez@gmail.com, Apr 25, 2005.

  1. Guest

    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
     
    , Apr 25, 2005
    #1
    1. Advertising

  2. In article <>,
    <> wrote:

    >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
     
    Richard Tobin, Apr 25, 2005
    #2
    1. Advertising

  3. 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
     
    David Carlisle, Apr 25, 2005
    #3
  4. Guest

    Works like a charm. Thanks,
    / j
     
    , Apr 28, 2005
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    0
    Views:
    1,470
  2. Alastair Cameron
    Replies:
    1
    Views:
    7,417
    SQL Server Development Team [MSFT]
    Jul 8, 2003
  3. CB
    Replies:
    1
    Views:
    592
    Johannes Koch
    Oct 2, 2003
  4. Michael Reiche
    Replies:
    3
    Views:
    10,857
    Michael Reiche
    Feb 5, 2004
  5. Tjerk Wolterink
    Replies:
    2
    Views:
    1,440
    Dimitre Novatchev
    Aug 24, 2006
Loading...

Share This Page