yml2/yslt.yml2
author Hartmut Goebel <h.goebel@crazy-compilers.com>
Thu, 27 Oct 2016 13:33:48 +0200
changeset 44 4e5f42d51cc4
parent 43 fb35b9db9ca1
child 51 34b48b90628c
permissions -rw-r--r--
docs: Include files are always searched at standard location, too.

This removes the need to specify the location where yml2 was unpacked or
installed as YML_PATH. So this now works:

YML_PATH=/foo ./yml2proc --xml2yml

The standard system location <prefix>/share/yml2 is now always appended to
the include search path. If this path does not exist, the directory one
above the `backend.py` file is added, allowing the same behaviour for
uninstalled yml2.

In the Makefile enforce the .ysl2 files to be searched in the current
directory first.
43
fb35b9db9ca1 Move data files into the Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff changeset
     1
// YSLT version 2.6.2
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
!!
fb35b9db9ca1 Move data files into the Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff changeset
     4
def indent(level):
fb35b9db9ca1 Move data files into the Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff changeset
     5
    return "value 'substring($space, 1, $_indent+" + str(level) + "*$autoindent)';"
fb35b9db9ca1 Move data files into the Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff changeset
     6
!!
fb35b9db9ca1 Move data files into the Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff changeset
     7
fb35b9db9ca1 Move data files into the Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff changeset
     8
in exsl decl document(href, method) alias document;
fb35b9db9ca1 Move data files into the Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff changeset
     9
in func decl def(name) alias function, result(select);
fb35b9db9ca1 Move data files into the Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff changeset
    10
fb35b9db9ca1 Move data files into the Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff changeset
    11
decl debug_off(exclude-result-prefixes="yml");
fb35b9db9ca1 Move data files into the Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff changeset
    12
fb35b9db9ca1 Move data files into the Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff changeset
    13
in xsl {
fb35b9db9ca1 Move data files into the Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff changeset
    14
    decl _trace_param(%text, name="yml:trace", select='yml:debug("* %text")') alias param;
fb35b9db9ca1 Move data files into the Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff changeset
    15
    decl _trace_with is _trace_param alias with-param;
fb35b9db9ca1 Move data files into the Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff changeset
    16
fb35b9db9ca1 Move data files into the Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff changeset
    17
    decl param(name, select);
fb35b9db9ca1 Move data files into the Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff changeset
    18
    decl const(name, select) alias variable, variable is const;
fb35b9db9ca1 Move data files into the Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff changeset
    19
    decl output(method), key(name, match, use);
fb35b9db9ca1 Move data files into the Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff changeset
    20
    decl value(select) alias value-of, copy(select) alias copy-of;
fb35b9db9ca1 Move data files into the Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff changeset
    21
fb35b9db9ca1 Move data files into the Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff changeset
    22
    decl indent is value(%level, select='substring($space, 1, $_indent + (%level) * $autoindent)');
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
    decl stylesheet(
fb35b9db9ca1 Move data files into the Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff changeset
    25
        *output="xml",
fb35b9db9ca1 Move data files into the Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff changeset
    26
        version="1.0",
fb35b9db9ca1 Move data files into the Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff changeset
    27
        xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
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
        output *output;
fb35b9db9ca1 Move data files into the Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff changeset
    30
        const "space", !"'" + " " * 200 + "'"!;
fb35b9db9ca1 Move data files into the Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff changeset
    31
        param "autoindent", 4;
fb35b9db9ca1 Move data files into the Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff changeset
    32
        content;
fb35b9db9ca1 Move data files into the Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff changeset
    33
    };
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
    decl estylesheet is stylesheet (
fb35b9db9ca1 Move data files into the Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff changeset
    36
        xmlns:exsl='http://exslt.org/common',
fb35b9db9ca1 Move data files into the Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff changeset
    37
        xmlns:math='http://exslt.org/math',
fb35b9db9ca1 Move data files into the Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff changeset
    38
        xmlns:func='http://exslt.org/functions',
fb35b9db9ca1 Move data files into the Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff changeset
    39
        xmlns:str='http://exslt.org/strings',
fb35b9db9ca1 Move data files into the Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff changeset
    40
        xmlns:dyn='http://exslt.org/dynamic',
fb35b9db9ca1 Move data files into the Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff changeset
    41
        xmlns:set='http://exslt.org/sets',
fb35b9db9ca1 Move data files into the Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff changeset
    42
        xmlns:sets='http://exslt.org/sets',
fb35b9db9ca1 Move data files into the Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff changeset
    43
        xmlns:date='http://exslt.org/dates-and-times',
fb35b9db9ca1 Move data files into the Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff changeset
    44
        xmlns:yml='http://fdik.org/yml',
fb35b9db9ca1 Move data files into the Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff changeset
    45
        extension-element-prefixes='exsl func str dyn set sets math date yml'
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
    decl textstylesheet is estylesheet(*output="text") {
fb35b9db9ca1 Move data files into the Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff changeset
    49
        output *output;
fb35b9db9ca1 Move data files into the Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff changeset
    50
        const "space", !"'" + " " * 200 + "'"!;
fb35b9db9ca1 Move data files into the Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff changeset
    51
        param "autoindent", 4;
fb35b9db9ca1 Move data files into the Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff changeset
    52
        xsl:template match="text()";
fb35b9db9ca1 Move data files into the Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff changeset
    53
        content;
fb35b9db9ca1 Move data files into the Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff changeset
    54
    }, tstylesheet is textstylesheet;
fb35b9db9ca1 Move data files into the Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff changeset
    55
fb35b9db9ca1 Move data files into the Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff changeset
    56
    decl template(match) {
fb35b9db9ca1 Move data files into the Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff changeset
    57
        _trace_param *_trace_info;
fb35b9db9ca1 Move data files into the Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff changeset
    58
        param "_indent", 0;
fb35b9db9ca1 Move data files into the Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff changeset
    59
        content;
fb35b9db9ca1 Move data files into the Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff changeset
    60
    };
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
    decl function(name) alias template {
fb35b9db9ca1 Move data files into the Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff changeset
    63
        _trace_param *_trace_info;
fb35b9db9ca1 Move data files into the Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff changeset
    64
        param "_indent", 0;
fb35b9db9ca1 Move data files into the Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff changeset
    65
        content;
fb35b9db9ca1 Move data files into the Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff changeset
    66
    };
fb35b9db9ca1 Move data files into the Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff changeset
    67
   
fb35b9db9ca1 Move data files into the Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff changeset
    68
    decl call(name) alias call-template {
fb35b9db9ca1 Move data files into the Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff changeset
    69
        _trace_with *_trace_info;
fb35b9db9ca1 Move data files into the Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff changeset
    70
        content;
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
    decl namespace_alias(stylesheet-prefix, result-prefix);
fb35b9db9ca1 Move data files into the Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff changeset
    74
    decl text, raw(disable-output-escaping='yes') alias text;
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
    decl with(name, select) alias with-param;
fb35b9db9ca1 Move data files into the Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff changeset
    77
    decl withIndent(%level, name="_indent", select='$_indent + (%level) * $autoindent') alias with-param;
fb35b9db9ca1 Move data files into the Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff changeset
    78
fb35b9db9ca1 Move data files into the Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff changeset
    79
    decl apply(select, *indent=1) alias apply-templates {
fb35b9db9ca1 Move data files into the Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff changeset
    80
        _trace_with *_trace_info;
fb35b9db9ca1 Move data files into the Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff changeset
    81
        withIndent *indent;
fb35b9db9ca1 Move data files into the Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff changeset
    82
        content;
fb35b9db9ca1 Move data files into the Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff changeset
    83
    };
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
    decl choose, when(test), otherwise;
fb35b9db9ca1 Move data files into the Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff changeset
    86
    decl if(test);
fb35b9db9ca1 Move data files into the Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff changeset
    87
    decl for(select) alias for-each, foreach is for;
fb35b9db9ca1 Move data files into the Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff changeset
    88
    decl element(name, namespace);
fb35b9db9ca1 Move data files into the Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff changeset
    89
    decl attrib(name, namespace) alias attribute, attrib_set(name) alias attribute-set;
fb35b9db9ca1 Move data files into the Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff changeset
    90
    decl processing(name) alias processing-instruction;
fb35b9db9ca1 Move data files into the Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff changeset
    91
    decl comment;
fb35b9db9ca1 Move data files into the Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff changeset
    92
    decl number(value), sort(select), decimal_format(name, decimal-separator=".", grouping-separator=",");
fb35b9db9ca1 Move data files into the Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff changeset
    93
    decl import(href), fallback;
fb35b9db9ca1 Move data files into the Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff changeset
    94
    decl message, error is message(terminate='yes'), warning is message(terminate='no');
fb35b9db9ca1 Move data files into the Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff changeset
    95
fb35b9db9ca1 Move data files into the Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff changeset
    96
    decl debug(%text, select='yml:debug(%text)') alias value-of;
fb35b9db9ca1 Move data files into the Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff changeset
    97
    decl assert(%test, %msg="''", select='yml:assert(%test,%msg)') alias value-of;
fb35b9db9ca1 Move data files into the Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff changeset
    98
}
fb35b9db9ca1 Move data files into the Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff changeset
    99
fb35b9db9ca1 Move data files into the Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff changeset
   100
define operator "«(.*?)»" as value "%1";
fb35b9db9ca1 Move data files into the Python package.
Hartmut Goebel <h.goebel@crazy-compilers.com>
parents:
diff changeset
   101