Project

Profile

Help

lack of current() in standalone XPath

Added by Anonymous over 16 years ago

Legacy ID: #4588662 Legacy Poster: Joseph Thomas-Kerr (jak09)

Hi, I'm wondering if anyone can shed any light on why current() isn't part of XPath 2.0? Are there some vagaries of the semantics of "context" that are different from XSLT that mean this function can't be used? Or is it just a quirk? I'd like to be able to say preceding::avc:sequenceParameterSet[avc:seq_parameter_set_id = current()/preceding::avc:pictureParameterSet[avc:pic_parameter_set_id = current()/avc:pic_parameter_set_id][1]/avc:seq_parameter_set_id][1] But because I'm not in XSLT (its actually a language called BSDL), I can't use current which means I'm forced to use preceding::avc:sequenceParameterSet[avc:seq_parameter_set_id = /avc:h264/avc:pictureParameterSet[avc:pic_parameter_set_id = /avc:h264/avc:slice[last()]/avc:pic_parameter_set_id][last()] /avc:seq_parameter_set_id][1] What these messes are attempting to do is to dereference two pointers (ids): slice->pictureParameterSet->sequenceParameterSet. The catch is that both parameter sets can be updated, so we always need to access the most recent one with a matching id. The 2nd expression is definitely O(n^2) (I've measured it). I suspect that the first one is too, so my earlier question may be a red herring. So maybe I'll ask two more: 1. Is there an O(n) way to do this (n is the length of the XML document)? 2. Is the O(n^2) complexity that I have measured an implementation issue, or is it inherent in the XPath? Regards, Joe.


Replies (1)

RE: lack of current() in standalone XPath - Added by Anonymous over 16 years ago

Legacy ID: #4588700 Legacy Poster: Michael Kay (mhkay)

>I'm wondering if anyone can shed any light on why current() isn't part of XPath 2.0? No idea. It wasn't in XPath 1.0 and no-one ever asked for it to be added to 2.0. What you can do, and it's not very pretty, is for $current in . return preceding::avc:sequenceParameterSet[avc:seq_parameter_set_id = $current/preceding::avc:pictureParameterSet[avc:pic_parameter_set_id = $current/avc:pic_parameter_set_id][1]/avc:seq_parameter_set_id][1] 1. Is there an O(n) way to do this (n is the length of the XML document)? Try Saxon-SA, which will probably try to build an index for this. Though that might not help, hard to be sure without understanding the data better. 2. Is the O(n^2) complexity that I have measured an implementation issue, or is it inherent in the XPath? See answer to (1)! Basically the "naive" execution strategy is O(n^2), a smart processor might do better but you can never rely on it. Are you sure you need preceding rather that preceding-sibling? That could make a big difference, though it would still be O(n^2). There might be a more efficient expression, I haven't really tried to analyze the problem. That's really one for xsl-list at mulberrytech.com, not for here. Michael Kay

    (1-1/1)

    Please register to reply