Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XML
|
XML General XML discussions.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XML 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 June 8th, 2006, 05:12 PM
Registered User
 
Join Date: Jun 2006
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default nested xPath

I have this xml:

<?xml version="1.0" encoding="ISO-8859-1" ?>
<root>
        <classes>
                <class name="math">
                        <lesson id="7" />
                        <lesson id="8" />
                        <lesson id="9" />
                </class>
                <class name="history">
                        <lesson id="15"/>
                        <lesson id="16"/>
                </class>
        </classes>
        <classlist>
                <lesson id="15">
                        <title>1900</title>
                </lesson >
                <lesson id="16">
                        <title>1800</title>
                </lesson >
                <lesson id="7">
                        <title>pitagoras</title>
                </lesson >

        </classlist>
</root>

I want nodelist object containing all lessons titles that belongs to the band “history”.

I need some help with the nested root of the xPath.
I know this: ("//lesson [@id = ???]/title")
What do I need to write instead of the ??? so it extract the right id numbers?

Many thanks


Janiv
 
Old June 8th, 2006, 05:22 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

/classlist/lesson[@id=/classes/class[@name='history']/lesson/@id]

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old June 8th, 2006, 05:31 PM
Registered User
 
Join Date: Jun 2006
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Sorry - it is not working.

Can you tell me the right syntax to extract the value of all the id's under the node: class?

The result should be :
7
8
9
15
16

Janiv
 
Old June 8th, 2006, 05:49 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

If it's not working, then let's work out why before we ask another question. What was your input, what was your stylesheet, and what was your output. If by "not working" you mean there was an error message, then what was hte error message?



Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old June 8th, 2006, 05:55 PM
Registered User
 
Join Date: Jun 2006
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default

not working = nothing was returned!

my second question related to the same issue: how do I extract attribute value.
in this case I mean the output shoud be
5

and not

id="5"

Janiv
 
Old June 8th, 2006, 06:26 PM
Registered User
 
Join Date: Jun 2006
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Do you need any other info, or my question is not clear?



Janiv





Similar Threads
Thread Thread Starter Forum Replies Last Post
xpath-nested expression vinod.kumbar RSS and Atom 0 July 8th, 2008 11:36 AM
XPath help migake XSLT 2 April 21st, 2006 10:49 AM
Nested XPath Expression sonicDace XML 9 January 8th, 2004 12:17 PM
help with XPath kend XSLT 2 July 15th, 2003 01:14 PM
XPath help itekcorp XML 1 June 17th, 2003 01:14 PM





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