469,275 Members | 1,871 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,275 developers. It's quick & easy.

getting parent node using XLST

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>


Jul 20 '05 #1
2 14672
john smith (pr**************@charter.net) 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.
Jul 20 '05 #2


<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
Jul 20 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by dannielum | last post: by
4 posts views Thread by Pavils Jurjans | last post: by
3 posts views Thread by Hai Nguyen | last post: by
reply views Thread by Guzeppi | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.