yslt.yml2
author Volker Birk <vb@pep.foundation>
Tue, 25 Apr 2017 20:46:59 +0200
changeset 9 0250d70228bc
parent 8 b49a28a57f67
child 38 90d687cbe277
permissions -rw-r--r--
...
4
e7b49a65cf3a Version 5.5
Volker Birk <vb@pep.foundation>
parents: 3
diff changeset
     1
// YSLT version 2.5.5
0
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',
8
Volker Birk <vb@pep.foundation>
parents: 4
diff changeset
    42
        xmlns:sets='http://exslt.org/sets',
0
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
    43
        xmlns:date='http://exslt.org/dates-and-times',
3
cf460d7c4417 adding yml namespace
Volker Birk <vb@pep.foundation>
parents: 0
diff changeset
    44
        xmlns:yml='http://fdik.org/yml',
9
Volker Birk <vb@pep.foundation>
parents: 8
diff changeset
    45
        extension-element-prefixes='exsl func str dyn set sets math date yml'
0
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
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
    48
    decl textstylesheet is estylesheet(*output="text") {
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
    49
        output *output;
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
    50
        const "space", !"'" + " " * 200 + "'"!;
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
    51
        param "autoindent", 4;
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
    52
        xsl:template "text()";
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
    53
        content;
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
    54
    }, tstylesheet is textstylesheet;
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
    55
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
    56
    decl template(match) {
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
    57
        _trace_param *_trace_info;
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
    58
        param "_indent", 0;
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
    59
        content;
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
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
    62
    decl function(name) alias template {
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
    63
        _trace_param *_trace_info;
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
    64
        param "_indent", 0;
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
    65
        content;
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
   
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
    68
    decl call(name) alias call-template {
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
    69
        _trace_with *_trace_info;
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
    70
        content;
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
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
    73
    decl namespace_alias(stylesheet-prefix, result-prefix);
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
    74
    decl text, raw(disable-output-escaping='yes') alias text;
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
    75
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
    76
    decl with(name, select) alias with-param;
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
    77
    decl withIndent(%level, name="_indent", select='$_indent + (%level) * $autoindent') alias with-param;
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
    78
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
    79
    decl apply(select, *indent=1) alias apply-templates {
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
    80
        _trace_with *_trace_info;
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
    81
        withIndent *indent;
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
    82
        content;
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
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
    85
    decl choose, when(test), otherwise;
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
    86
    decl if(test);
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
    87
    decl for(select) alias for-each, foreach is for;
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
    88
    decl element(name, namespace);
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
    89
    decl attrib(name, namespace) alias attribute, attrib_set(name) alias attribute-set;
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
    90
    decl processing(name) alias processing-instruction;
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
    91
    decl comment;
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
    92
    decl number(value), sort(select), decimal_format(name, decimal-separator=".", grouping-separator=",");
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
    93
    decl import(href), fallback;
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
    94
    decl message, error is message(terminate='yes'), warning is message(terminate='no');
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
    95
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
    96
    decl debug(%text, select='yml:debug(%text)') alias value-of;
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
    97
    decl assert(%test, %msg="''", select='yml:assert(%test,%msg)') alias value-of;
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
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   100
define operator "«(.*?)»" as value "%1";
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   101