yslt.yml2
author Volker Birk <vb@pep.foundation>
Tue, 23 Aug 2016 11:33:17 +0200
changeset 3 cf460d7c4417
parent 0 76005e62091d
child 4 e7b49a65cf3a
permissions -rw-r--r--
adding yml namespace
0
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
     1
// YSLT version 2.5.4
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
     2
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
     3
!!
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
     4
def indent(level):
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
     5
    return "value 'substring($space, 1, $_indent+" + str(level) + "*$autoindent)';"
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
     6
!!
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
     7
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
     8
in exsl decl document(href, method) alias document;
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
     9
in func decl def(name) alias function, result(select);
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
    10
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
    11
decl debug_off(exclude-result-prefixes="yml");
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
    12
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
    13
in xsl {
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
    14
    decl _trace_param(%text, name="yml:trace", select='yml:debug("* %text")') alias param;
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
    15
    decl _trace_with is _trace_param alias with-param;
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
    16
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
    17
    decl param(name, select);
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
    18
    decl const(name, select) alias variable, variable is const;
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
    19
    decl output(method), key(name, match, use);
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
    20
    decl value(select) alias value-of, copy(select) alias copy-of;
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
    21
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
    22
    decl indent is value(%level, select='substring($space, 1, $_indent + (%level) * $autoindent)');
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
    23
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
    24
    decl stylesheet(
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
    25
        *output="xml",
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
    26
        version="1.0",
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
    27
        xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
    28
    ) {
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
    29
        output *output;
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
    30
        const "space", !"'" + " " * 200 + "'"!;
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
    31
        param "autoindent", 4;
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
    32
        content;
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
    33
    };
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
    34
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
    35
    decl estylesheet is stylesheet (
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
    36
        xmlns:exsl='http://exslt.org/common',
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
    37
        xmlns:math='http://exslt.org/math',
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
    38
        xmlns:func='http://exslt.org/functions',
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
    39
        xmlns:str='http://exslt.org/strings',
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
    40
        xmlns:dyn='http://exslt.org/dynamic',
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
    41
        xmlns:set='http://exslt.org/sets',
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
    42
        xmlns:date='http://exslt.org/dates-and-times',
3
cf460d7c4417 adding yml namespace
Volker Birk <vb@pep.foundation>
parents: 0
diff changeset
    43
        xmlns:yml='http://fdik.org/yml',
cf460d7c4417 adding yml namespace
Volker Birk <vb@pep.foundation>
parents: 0
diff changeset
    44
        extension-element-prefixes='exsl func str dyn set math date yml'
0
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
    45
    );
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
    46
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
    47
    decl textstylesheet is estylesheet(*output="text") {
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
    48
        output *output;
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
    49
        const "space", !"'" + " " * 200 + "'"!;
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
    50
        param "autoindent", 4;
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
    51
        xsl:template "text()";
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
    52
        content;
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
    53
    }, tstylesheet is textstylesheet;
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
    54
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
    55
    decl template(match) {
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
    56
        _trace_param *_trace_info;
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
    57
        param "_indent", 0;
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
    58
        content;
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
    59
    };
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
    60
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
    61
    decl function(name) alias template {
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
    62
        _trace_param *_trace_info;
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
    63
        param "_indent", 0;
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
    64
        content;
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
    65
    };
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
    66
   
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
    67
    decl call(name) alias call-template {
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
    68
        _trace_with *_trace_info;
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
    69
        content;
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
    70
    };
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
    71
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
    72
    decl namespace_alias(stylesheet-prefix, result-prefix);
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
    73
    decl text, raw(disable-output-escaping='yes') alias text;
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
    74
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
    75
    decl with(name, select) alias with-param;
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
    76
    decl withIndent(%level, name="_indent", select='$_indent + (%level) * $autoindent') alias with-param;
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
    77
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
    78
    decl apply(select, *indent=1) alias apply-templates {
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
    79
        _trace_with *_trace_info;
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
    80
        withIndent *indent;
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
    81
        content;
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
    82
    };
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
    83
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
    84
    decl choose, when(test), otherwise;
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
    85
    decl if(test);
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
    86
    decl for(select) alias for-each, foreach is for;
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
    87
    decl element(name, namespace);
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
    88
    decl attrib(name, namespace) alias attribute, attrib_set(name) alias attribute-set;
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
    89
    decl processing(name) alias processing-instruction;
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
    90
    decl comment;
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
    91
    decl number(value), sort(select), decimal_format(name, decimal-separator=".", grouping-separator=",");
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
    92
    decl import(href), fallback;
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
    93
    decl message, error is message(terminate='yes'), warning is message(terminate='no');
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
    94
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
    95
    decl debug(%text, select='yml:debug(%text)') alias value-of;
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
    96
    decl assert(%test, %msg="''", select='yml:assert(%test,%msg)') alias value-of;
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
    97
}
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
    98
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
    99
define operator "«(.*?)»" as value "%1";
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   100