Project

General

Profile

« Previous | Next » 

Revision 1347

xpath_func.py: _forEach: Fixed to support _val replacements anywhere, by doing a string-based search-and-replace on a quoted XPath instead of a list-based search-and-replace on an already-parsed XPath

View differences:

lib/xpath_func.py
21 21
# Function names must start with _ to avoid collisions with real tags
22 22
# Functions take arguments (args, path)
23 23

  
24
for_repl_var = xpath.XpathElem('_val')
25

  
26 24
def _forEach(args, path):
27
    '''Replaces "_val" in `do` with each item in the `in_` list'''
25
    '''Replaces '_val' in `do` with each item in the `in_` list'''
28 26
    in_, do = args
29 27
    list_ = [in_[1:]] + in_[0].other_branches
28
    do = do[0].name
30 29
    
31 30
    for_path = []
32
    for with_ in list_: for_path += util.list_replace(do, for_repl_var, with_)
31
    for with_, in list_: for_path += xpath.parse(do.replace('_val', with_.name))
33 32
    return for_path + path
34 33
funcs['_forEach'] = _forEach

Also available in: Unified diff