Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > XML > XSLT
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old October 15th, 2006, 07:59 PM
Friend of Wrox
Points: 1,676, Level: 16
Points: 1,676, Level: 16 Points: 1,676, Level: 16 Points: 1,676, Level: 16
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jul 2006
Location: , , .
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
Reply With Quote
  #2 (permalink)  
Old October 16th, 2006, 02:27 AM
mhkay's Avatar
Wrox Author
Points: 18,487, Level: 59
Points: 18,487, Level: 59 Points: 18,487, Level: 59 Points: 18,487, Level: 59
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
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
Reply With Quote
  #3 (permalink)  
Old October 16th, 2006, 07:07 AM
Friend of Wrox
Points: 1,676, Level: 16
Points: 1,676, Level: 16 Points: 1,676, Level: 16 Points: 1,676, Level: 16
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jul 2006
Location: , , .
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

Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 01:51 AM.


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