getting parent node using XLST

Discussion in 'XML' started by john smith, May 3, 2005.

  1. john smith

    john smith Guest

    Hello,

    I am having trouble getting the parent node of an xml document using xslt.

    I am trying to return the node wine, but this does not return wine but the
    element values under wine.
    I thouht this would work. I am looking for the prices context and then ask
    for the parent node right?

    What am I doing wrong? Thanks in advance for your help.


    <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    version="2.0">

    <xsl:template match="prices">

    parent is: <xsl:value-of select="parent::node"/>

    </xsl:template>

    </xsl:stylesheet>



    <wine>
    <winery>Los Vascos</winery>
    <year>1998</year>
    <prices>
    <list>13.99</list>
    <discounted>11.99</discounted>
    <case>143.50</case>
    </prices>
    </wine>
     
    john smith, May 3, 2005
    #1
    1. Advertising

  2. john smith () wrote:
    : Hello,

    : I am having trouble getting the parent node of an xml document using xslt.

    : I am trying to return the node wine, but this does not return wine but the
    : element values under wine.
    : I thouht this would work. I am looking for the prices context and then ask
    : for the parent node right?

    : What am I doing wrong? Thanks in advance for your help.


    : <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    : version="2.0">

    : <xsl:template match="prices">

    : parent is: <xsl:value-of select="parent::node"/>


    select=".."


    : </xsl:template>

    : </xsl:stylesheet>



    : <wine>
    : <winery>Los Vascos</winery>
    : <year>1998</year>
    : <prices>
    : <list>13.99</list>
    : <discounted>11.99</discounted>
    : <case>143.50</case>
    : </prices>
    : </wine>





    --

    This space not for rent.
     
    Malcolm Dew-Jones, May 3, 2005
    #2
    1. Advertising

  3. <xsl:value-of select="parent::node"/>

    selects all parent elements that have name node.
    You meant
    <xsl:value-of select="parent::node()"/>
    although you could use
    <xsl:value-of select=".."/>

    The string value of the parent is the concatenation of all the character
    data of all the parent's descendants, is that really what you want?

    David
     
    David Carlisle, May 3, 2005
    #3
    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,616
  2. Tjerk Wolterink
    Replies:
    2
    Views:
    1,477
    Dimitre Novatchev
    Aug 24, 2006
  3. Malcolm Dew-Jones
    Replies:
    1
    Views:
    390
    Joseph Kesselman
    Feb 27, 2008
  4. Replies:
    2
    Views:
    837
    Martin Honnen
    Mar 17, 2008
  5. John Bankhead

    Null parent node on custom tree node after populate on demand

    John Bankhead, Dec 4, 2006, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    293
    John Bankhead
    Dec 4, 2006
Loading...

Share This Page