Altova Mailing List Archives>Archive Index >comp.text.xml Archive Home >Recent entries >Thread Prev - Re: Returning "nearest in document" matches using XPath [Thread Next] Re: Returning "nearest in document" matches using XPathTo: NULL Date: 12/5/2008 5:48:00 PM Nick Leverton escribió: > I have an application which attempts to describe a tree of TCP subnets, > which in essence are not fully accessible from each other. I have a > description of the network in XML as shown in the excerpt below. > ... > > <?xml version="1.0"?> > <nodes> > <node id="V9990" ip="1.1.1.1"> > <unit id="23" ip="10.10.10.10"/> > <unit id="24" ip="10.10.10.11"/> > <node id="V9991" ip="10.10.10.12"> > <unit id="26" ip="192.168.0.1"/> > <unit id="27" ip="192.168.0.2"/> > </node> > </node> > <node id="V9992" ip="2.2.2.2"> > <node id="V9993" ip="10.10.10.10"> > <unit id="21"/> > <unit id="22"/> > </node> > </node> > </nodes> > > To simplify network maintenance I would like to use the same config file > on all the "nodes", and to modify the XPath query with extra terms on > the sub-nodes. In other words, on the "root" machine a query for id=26 > will return ip=1.1.1.1, but on node V9990 a query for id=26 will return > ip=10.10.10.12 > > In summary, what I want to do is to retrieve the nearest ip attribute > in the document which has a given id attribute as a descendant. I am > currently using the following XPath: > Nick Leverton escribió: > In article <4939431f$0$17068$6e1ede2f@r...>, > Dimitre Novatchev <dnovatchev@c...> wrote: >> What do you mean by "nearest"? Is this the geographical distance b/n two >> nodes? I dont see this reflected in the XML document. > > No, sorry for being unclear. I mean that from the set of ip attributes > on the axis which contains both the root and the required id attribute: > > / ... @ip ... @ip ... @ip ... @id > > I want to find the left-most one in the above diagram, nearest to the root > (or to other selected starting node inbetween the root and the required @id). So you mean: inside the context node, find the IP of the outermost "node" that contains the destination "unit". The XPath for this could be (untested): ./descendant::node[.//unit[@id="26"]]/@ip Is that what you want? -- Manuel Collado - http://lml.ls.fi.upm.es/~mcollado | ||||||
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | Mobile | Full Site | |||
|
