On Wednesday 11 January 2006 16:10, Vladimir Blagojevic wrote: > Hi, > > I am new to PyXml and I am struggling with xpath evaluation. Namely, > if I pass a node to the Evaluate function instead of the whole > document, I would expect the xpath evaluation to start from that node, > not from its containing document. > > Let me illustrate my problem with an example: > > doc = > minidom.parseString('<table><tr><td><table><tr/></table></td></tr><tr/></ta >ble>') print len(xpath.Evaluate('//tr', doc.documentElement)) > 3 > td = xpath.Evaluate('//td', doc.documentElement)[0] > print len(xpath.Evaluate('//tr', td)) > 3 > > I would expect 1, since the td element only contains onew descendant > tr element. > > If one looks at the code of ParsedAbbreviatedAbsoluteLocationPath.py, > we see why: > > root = context.node.ownerDocument or context.node > > I would expect this to read: > > root = context.node or context.node.ownerDocument
If you change your expression to read ".//tr", an AbbreviatedRelativeLocationPath, you should get the result you are expecting. -- Jeremy Kloth http://fourthought.com/ http://4suite.org/ _______________________________________________ XML-SIG maillist - XML-SIG@python.org http://mail.python.org/mailman/listinfo/xml-sig