use sibling node attribute value in XPath query

LostProgrammer

Well-known member
Joined
Jan 17, 2003
Messages
123
I want to select a node set base on the attribute value of a sibling node.
I have a nodes
<Table Name=Customers>
<Field Name=CustomerId/>
<Field Name=AccountNumber/>
</Table>

<ExtendedDataType>
<Table Name=Customers/>
<Field Name=CustomerId/>
</ExtendedDataType>

This query returns all of the Property nodes from the Customers table:
/xs:Tables/xs:Table[attribute::Name=Customers]/xs:Propertys/xs:Property

I want to replace Customers with
parent::Table[attribute::Name] resulting in something like
/xs:Tables/xs:Table[attribute::Name=parent::Table[attribute::Name]/xs:Propertys/xs:Property

so that I can filter the choices for Field of ExtendedDataType by using the Table Name that has already been selected.

can this be done? do i need a variable or something?
Thanks for the help,
lp
 
...predicate evaluation

if n is the current node:
This returns a nodelist with the correct nodes
Code:
n.SelectNodes("/xs:ObjectTree/xs:DataDictionary/xs:Tables/xs:Table[attribute::Name=Customers]/xs:Propertys/xs:Property", nsmgr)
...And this prints Customers
Code:
    Dim child As XmlNode
    child  = n.SelectSingleNode("parent::node()/xs:Table", nsmgr)
    MsgBox(child .Attributes("Name").Value)
when i replace Customers with "parent::node()/xs:Table/@Name" giving

Code:
n.SelectNodes("/xs:ObjectTree/xs:DataDictionary/xs:Tables/xs:Table[attribute::Name=parent::node()/xs:Table/@Name]/xs:Propertys/xs:Property", nsmgr)
I get a list of all Property Nodes from all Table/Propertys not a filtered list.
Shouldnt parent::node()/xs:Table/@Name evaluate to Customers in the expression?

thanks,
lp
 
Last edited by a moderator:
same problem, different issue

so heres what i left with
Code:
xs:ObjectTree/xs:DataDictionary/xs:Tables/xs:Table[attribute::Name=parent::node()/xs:Table/@Name]/xs:Propertys/xs:Property"
the expression is evaluating correctly, however not like i initially thought.
it seems that the reference to parent::node() is the parent of the current Table node, not the parent of the the original context. I can only assume that the xs:ObjectTree/xs:DataDictionary/xs:Tables/xs:Table changes the context of the expression.
So the question becomes, how do i reference the original context node after some traversal of the tree(objecttree/datadictionary/tables/table)?
 
Last edited by a moderator:
Back
Top