getting parent node using XLST

J

john smith

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>
 
M

Malcolm Dew-Jones

john smith ([email protected]) 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>
 
D

David Carlisle

<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
 

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

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,011
Latest member
AjaUqq1950

Latest Threads

Top