Project

General

Profile

« Previous | Next » 

Revision 33

data2xml: Created simplify_xpath script to remove duplication from XPath expressions

View differences:

scripts/data2xml/simplify_xpath
1
#!/usr/bin/env python
2
# Removes duplication from XPath expressions
3

  
4
import re
5
import sys
6

  
7
def main():
8
    while True:
9
        line = sys.stdin.readline()
10
        if line == '': break
11
        # Forward * abbrs
12
        line = re.sub(r'(/)(\w+)(?=\w*(?:->/[^/]*)?/\2\b)', r'\1*', line)
13
        # Backward * abbrs
14
        line = re.sub(r'(/(\w+)->/[^/]*/[^/]*\[)\2', r'\1*', line)
15
        sys.stdout.write(line)
16

  
17
main()
0 18

  

Also available in: Unified diff