Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 15th, 2006, 07:59 PM
Friend of Wrox
 
Join Date: Jul 2006
Posts: 430
Thanks: 28
Thanked 5 Times in 5 Posts
Send a message via Yahoo to bonekrusher
Default Select ancestor Node

Hi All,

I am having trouble selecting a node with xpath. I hope someone can help. Here is my xml sample:

Code:
<Book>
    <Chapter>
        <revNumber>
            <number>03</number>
        </revNumber>
        <RevDate>
            <date>2006-09-12 </date>
        </RevDate>
        <Sec1/>
        <Sec1>
            <Para>
                <Bullet1>
                    <Para id="chg3">Administrator</Para>
                </Bullet1>
            </Para>
            <Title>REVISIONS:</Title>
        </Sec1>
    </Chapter>
</Book>
I want to grab the value of 'Title'. I tried the following to grab the title if the Para ID='chg3':

<xsl:for-each select="//JBU:Para[@id='chg3']">
    <xsl:variable name="sectiontitle" select="../JBU:Title"/>
    <xsl:variable name="oldtext" select="."/>
    <td>
        <xsl:value-of select="$oldtext"/>
    </td>
    <td>
        <xsl:value-of select="$sectiontitle"/>
    </td>
</xsl:for-each>

I do not return a value. However if Para is a direct child of of Sec1, it returns a value.

Thanks for the help.
Bones
 
Old October 16th, 2006, 02:27 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

Try replacing ".." with ancestor::JBU:Sec1

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old October 16th, 2006, 07:07 AM
Friend of Wrox
 
Join Date: Jul 2006
Posts: 430
Thanks: 28
Thanked 5 Times in 5 Posts
Send a message via Yahoo to bonekrusher
Default

Thank you Michael. I wasn't sure how to apply the Axis.

Regards,

Bones






Similar Threads
Thread Thread Starter Forum Replies Last Post
Select correct child node richieWolf XSLT 4 September 24th, 2008 08:53 AM
Select range node Christ M XSLT 4 January 25th, 2008 12:47 PM
XML: How to select a node with ' in it using Xpath guozai BOOK: Professional C#, 2nd and 3rd Editions 1 October 6th, 2006 12:37 PM
Help: Select every node except these nodes arcuza XSLT 8 May 25th, 2005 08:07 AM
select single node bcadmin BOOK: XSLT Programmer's Reference, 2nd Edition 1 November 10th, 2004 12:15 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.