Subject:XPath descendant question Author:George George Date:11 May 2013 10:49 AM
Dear All,
I am confused as to why XStylus returns this results when running a query regarding the descendant axis.
I have the following XML file:
<?xml version=”1.0”?>
<!DOCTYPE BookStore System “BookStore.dtd”>
<BookStore
BookStoreID=”BS112”
Name =”CheapBooks”
Location=”London”
OwnerName =”Mr. Black”>
<Books
BookID =”BK111”
Title=”Introduction to reading”
Authors =”Ian Green”>
</Books>
<Books
BookID =”BK112”
Title=”Introduction to Sleeping”
Authors =”Peter White”>
</Books>
<Staff
StaffID =”S333”
Name =”Ana Car” >
<Manager ManagerID=”MG444”
Name = “Mrs White”
Address = “150 Wide Road, London SW10”>
</Manager>
</Staff>
</BookStore>
The document is well-formed and validates fine according to the tool. Now, I want to find the member of staff managed by the manager with ManagerID equal to MG444.
I use the following query:
/child::BookStore/descendant:Staff[@ManageID='MG444']; my rationale been that I am looking for the child element of BookStore that has a Staff descendant which has a ManagerID attribute with the specific value. Stylus Studio returns nothing. If I run /child::BookStore/descendant:Staff, I get the whole Staff element, not just Manager. Why is that - is descendant not supposed to only look at descendants, not the current node and ignore attributes? Likewise, why does the first query does not work?
Subject:XPath descendant question Author:Ivan Pedruzzi Date:12 May 2013 07:48 PM
In the XML sample there are few problems
in the DTD declaration system has to be all uppercase
<!DOCTYPE BookStore SYSTEM "booktore.dtd">
You also may have copy and paste the XML frmagment from Word or some other editor which turned " to ” amd made the XML not well formed
The shorthand expression you are looking for is the following, which returns Staff elements that has at least one direct child Manager with attribute ManagarID equal to MG444