Project

General

Profile

1
#!/usr/bin/env python
2
# Removes duplication from XPath expressions
3
# Filters one XPath per line from stdin to stdout
4

    
5
import re
6
import sys
7

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

    
18
main()
(45-45/57)