yml2/xml2yml.ysl2
author Volker Birk <vb@pep-project.org>
Tue, 15 Dec 2020 11:30:47 +0100
changeset 69 2a1581de91ea
parent 43 fb35b9db9ca1
permissions -rw-r--r--
do not need this
43
fb35b9db9ca1 Move data files into the Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff changeset
     1
// xml2yml2.ysl2 version 2.4.4
fb35b9db9ca1 Move data files into the Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff changeset
     2
fb35b9db9ca1 Move data files into the Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff changeset
     3
include yslt.yml2
fb35b9db9ca1 Move data files into the Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff changeset
     4
fb35b9db9ca1 Move data files into the Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff changeset
     5
decl textstylesheet is estylesheet(*output="text") {
fb35b9db9ca1 Move data files into the Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff changeset
     6
    output *output;
fb35b9db9ca1 Move data files into the Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff changeset
     7
    const "space", !"'" + " " * 200 + "'"!;
fb35b9db9ca1 Move data files into the Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff changeset
     8
    param "autoindent", 4;
fb35b9db9ca1 Move data files into the Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff changeset
     9
    content;
fb35b9db9ca1 Move data files into the Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff changeset
    10
}, tstylesheet is textstylesheet;
fb35b9db9ca1 Move data files into the Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff changeset
    11
fb35b9db9ca1 Move data files into the Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff changeset
    12
define operator "†" as call "convert" with "tag", "name()";
fb35b9db9ca1 Move data files into the Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff changeset
    13
fb35b9db9ca1 Move data files into the Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff changeset
    14
tstylesheet {
fb35b9db9ca1 Move data files into the Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff changeset
    15
    function "printNS"
fb35b9db9ca1 Move data files into the Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff changeset
    16
        for "*/namespace::*[local-name()!='xml']" {
fb35b9db9ca1 Move data files into the Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff changeset
    17
            > xmlns
fb35b9db9ca1 Move data files into the Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff changeset
    18
            if "not(local-name()='')"
fb35b9db9ca1 Move data files into the Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff changeset
    19
                > :«local-name()»
fb35b9db9ca1 Move data files into the Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff changeset
    20
            > ="«.»"
fb35b9db9ca1 Move data files into the Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff changeset
    21
            if "position()<last()" > , 
fb35b9db9ca1 Move data files into the Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff changeset
    22
        }
fb35b9db9ca1 Move data files into the Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff changeset
    23
    
fb35b9db9ca1 Move data files into the Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff changeset
    24
    template "/" {
fb35b9db9ca1 Move data files into the Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff changeset
    25
        if "count(*/namespace::*)>1" {
fb35b9db9ca1 Move data files into the Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff changeset
    26
            | decl «name(*)»(`call "printNS"`);
fb35b9db9ca1 Move data files into the Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff changeset
    27
            |
fb35b9db9ca1 Move data files into the Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff changeset
    28
        }
fb35b9db9ca1 Move data files into the Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff changeset
    29
        apply "*", 0;
fb35b9db9ca1 Move data files into the Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff changeset
    30
    }
fb35b9db9ca1 Move data files into the Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff changeset
    31
fb35b9db9ca1 Move data files into the Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff changeset
    32
    template "text()" {
fb35b9db9ca1 Move data files into the Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff changeset
    33
        param "text", "normalize-space()";
fb35b9db9ca1 Move data files into the Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff changeset
    34
fb35b9db9ca1 Move data files into the Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff changeset
    35
        if "string-length($text)>0" choose {
fb35b9db9ca1 Move data files into the Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff changeset
    36
            when "contains($text,'\\n')" choose {
fb35b9db9ca1 Move data files into the Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff changeset
    37
                when "string-length(substring-before($text,'\\n'))<string-length($text)-1" choose {
fb35b9db9ca1 Move data files into the Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff changeset
    38
                    when "substring($text,string-length($text),1)='\\n'"
fb35b9db9ca1 Move data files into the Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff changeset
    39
                        > \n||\n«$text»||\n\n
fb35b9db9ca1 Move data files into the Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff changeset
    40
                    otherwise > > «str:replace($text,'\\n','\\\\n')»\n
fb35b9db9ca1 Move data files into the Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff changeset
    41
                }
fb35b9db9ca1 Move data files into the Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff changeset
    42
                otherwise > | «$text»\n
fb35b9db9ca1 Move data files into the Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff changeset
    43
            }
fb35b9db9ca1 Move data files into the Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff changeset
    44
            otherwise > > `copy "."`\n
fb35b9db9ca1 Move data files into the Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff changeset
    45
        }
fb35b9db9ca1 Move data files into the Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff changeset
    46
    }
fb35b9db9ca1 Move data files into the Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff changeset
    47
fb35b9db9ca1 Move data files into the Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff changeset
    48
    template "*" {
fb35b9db9ca1 Move data files into the Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff changeset
    49
        0>
fb35b9db9ca1 Move data files into the Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff changeset
    50
        call "convert" with "tag", "name()";
fb35b9db9ca1 Move data files into the Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff changeset
    51
        apply "@*";
fb35b9db9ca1 Move data files into the Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff changeset
    52
fb35b9db9ca1 Move data files into the Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff changeset
    53
        choose {
fb35b9db9ca1 Move data files into the Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff changeset
    54
            when "count(*)=0 and string-length(normalize-space())=0"
fb35b9db9ca1 Move data files into the Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff changeset
    55
                > ;\n
fb35b9db9ca1 Move data files into the Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff changeset
    56
            when "count(*)=1 and string-length(normalize-space())=0" {
fb35b9db9ca1 Move data files into the Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff changeset
    57
                > \n
fb35b9db9ca1 Move data files into the Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff changeset
    58
                apply "*";
fb35b9db9ca1 Move data files into the Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff changeset
    59
            }
fb35b9db9ca1 Move data files into the Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff changeset
    60
            when "count(*)=0 and string-length(normalize-space())>0" {
fb35b9db9ca1 Move data files into the Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff changeset
    61
                >  
fb35b9db9ca1 Move data files into the Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff changeset
    62
                apply "text()";
fb35b9db9ca1 Move data files into the Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff changeset
    63
            }
fb35b9db9ca1 Move data files into the Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff changeset
    64
            otherwise {
fb35b9db9ca1 Move data files into the Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff changeset
    65
                >  {\n
fb35b9db9ca1 Move data files into the Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff changeset
    66
                for "*|text()" {
fb35b9db9ca1 Move data files into the Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff changeset
    67
                    if "local-name()=''"
fb35b9db9ca1 Move data files into the Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff changeset
    68
                        if "string-length(normalize-space())>0"
fb35b9db9ca1 Move data files into the Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff changeset
    69
                            1>
fb35b9db9ca1 Move data files into the Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff changeset
    70
                    apply ".";
fb35b9db9ca1 Move data files into the Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff changeset
    71
                }
fb35b9db9ca1 Move data files into the Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff changeset
    72
                | }
fb35b9db9ca1 Move data files into the Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff changeset
    73
            }
fb35b9db9ca1 Move data files into the Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff changeset
    74
        }
fb35b9db9ca1 Move data files into the Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff changeset
    75
    }
fb35b9db9ca1 Move data files into the Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff changeset
    76
fb35b9db9ca1 Move data files into the Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff changeset
    77
    template "@*" {
fb35b9db9ca1 Move data files into the Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff changeset
    78
        >  «name()»="«.»"
fb35b9db9ca1 Move data files into the Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff changeset
    79
        if "position()<last()" > ,
fb35b9db9ca1 Move data files into the Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff changeset
    80
    }
fb35b9db9ca1 Move data files into the Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff changeset
    81
fb35b9db9ca1 Move data files into the Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff changeset
    82
    function "convert" {
fb35b9db9ca1 Move data files into the Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff changeset
    83
        param "tag";
fb35b9db9ca1 Move data files into the Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff changeset
    84
fb35b9db9ca1 Move data files into the Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff changeset
    85
        > «translate($tag, '-', '_')»
fb35b9db9ca1 Move data files into the Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff changeset
    86
    }
fb35b9db9ca1 Move data files into the Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff changeset
    87
}