yslt.en.yhtml2
author Volker Birk <vb@pep-project.org>
Mon, 04 Nov 2019 11:38:34 +0100
changeset 40 432ab62b2537
parent 0 76005e62091d
permissions -rw-r--r--
date
0
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
     1
include homepage.en.yhtml2
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
page "YSLT – XSLT C style" {
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
     4
    h1 id=intro > YSLT – an introduction
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
     5
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
     6
    p   >>
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
     7
        Especially the ¬http://www.w3.org/TR/xslt XSLT¬ programmer can benefit from YML.
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
     8
        Usually many attributes of XSLT are annoying in programming praxis:
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
     9
        >>
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
    ul {
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
    12
        li  >>
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
    13
            the missing separation of ¬http://en.wikipedia.org/wiki/Indent_style indention¬
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
    14
            of the XSLT program and indention of the output text
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
    15
            >>
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
        li > the complicated syntax
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
    18
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
    19
        li > the lack of good text escaping mechanisms (< and > are not seldom)
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
    20
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
    21
        li > ...
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
    22
    }
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
    p > In short, it's ugly ;-)
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
    25
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
    26
    p   >>
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
    27
        Usually the result is, that many programmers are avoiding XSLT as a programming language.
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
    28
        It's a pity, because for processing XML data, it can do much more than “formatting” as
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
    29
        “stylesheets”.
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
    30
        >>
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
    31
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
    32
    p   >>
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
    33
        The idea of YSLT now is to supply a simple language, which programmers want to use, to
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
    34
        make the features of XSLT accessible to a broader base of people.
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
    35
        >>
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
    36
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
    37
    p   >>
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
    38
        YSLT can be used much simpler; it's just a ¬http://fdik.org/yml/index#ylanguages Y Language¬
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
    39
        for XSLT. I'm using it for my blog, here you can ¬http://fdik.org/yblog2.tar.bz2 download YBlog2¬,
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
    40
        a simple blogging software in YSLT.
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
    41
        >>
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
    42
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
    43
    p > Here you can find the ¬yslt.yml2 YSLT specification¬.
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
    44
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
    45
    h2 id=hello > Hello, World
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
    p > In YSLT, the hello world program reads like this:
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
    48
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
    49
    Code    ||
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
    50
            include yslt.yml2
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
    51
            textstylesheet template "/" | hello, world
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
    52
            ||
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
    53
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
    54
    p   >>
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
    55
        The `a href="http://fdik.org/yml/features#including" code > include` line includes the
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
    56
        YSLT Y Language declarations. The second line generates an XSLT hello world program.
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
    57
        You can generate it using:
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
    58
        >>
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
    Code | % yml2c -o hello.xsl hello.ysl2
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
    p > This results in the following program:
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
    63
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
    64
    Code    ||
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
    65
            <xsl:stylesheet xmlns:func="http://exslt.org/functions"
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
    66
            xmlns:dyn="http://exslt.org/dynamic" xmlns:str="http://exslt.org/strings"
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
    67
            xmlns:math="http://exslt.org/math"
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
    68
            xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
    69
            extension-element-prefixes="exsl func str dyn set math"
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
    70
            xmlns:set="http://exslt.org/sets" version="1.0"
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
    71
            xmlns:exsl="http://exslt.org/common"><xsl:output method="text"/>
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
    72
            <xsl:variable name="space" select="'                                 '"/>
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
    73
            <xsl:param name="autoindent" select="4"/><xsl:template match="/">
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
    74
            <xsl:param name="_indent" select="0"/><xsl:value-of
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
    75
            select="substring($space, 1, $_indent+0*$autoindent)"/>hello, world
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
    76
            </xsl:template></xsl:stylesheet>
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
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
    79
    p   >>
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
    80
        You can execute this program with any
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
    81
        ¬http://en.wikipedia.org/wiki/XML_template_engine XSL processor¬, for example the Free Software
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
    82
        ¬http://xmlsoft.org/XSLT/xsltproc2.html xsltproc¬.
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
    Code    ||
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
    86
            % yml2c -o hello.xsl hello.ysl2
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
    87
            % echo '<empty/>' > empty.xml          
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
    88
            % xsltproc hello.xsl empty.xml 
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
    89
            hello, world
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
    90
            % _
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
    91
            ||
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
    92
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
    93
    p   >>
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
    94
        Or you can just use ¬toolchain#processor yml2proc¬:
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
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
    97
    Code    ||
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
    98
            % yml2proc -My hello.ysl2
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
    99
            hello, world
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   100
            % _
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   101
            ||
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   102
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   103
    h2 id=programming > Programming in YSLT
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   104
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   105
    p   >>
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   106
        Because YSLT is just a ¬index#ylanguages Y Language¬ for XSLT, you can do anything with YSLT
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   107
        you can do with XSLT in just nicer syntax ;-) To read what XSLT is all about, I recommend 
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   108
        ¬http://www.w3.org/TR/xslt the official W3C documentation for XSLT¬.
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   109
        >>
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   110
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   111
    p   >>
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   112
        So this document is just an beginners guide, if you want to understand XSLT completely,
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   113
        better read the ¬http://www.w3.org W3C¬ stuff.
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   114
        >>
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   115
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   116
    h3 > Programming YSLT means programming with a pure functional language.
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   117
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   118
    p   >>
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   119
        Lovers of ¬http://en.wikipedia.org/wiki/Lisp_(programming_language) Lisp¬ or
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   120
        ¬http://www.haskell.org/ Haskell¬ will not see any problems. But many programmers are used to
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   121
        have a programming language with a
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   122
        ¬http://en.wikipedia.org/wiki/Procedural_programming procedural imperative paradigma¬ like
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   123
        ¬http://java.sun.com Java¬,
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   124
        ¬http://en.wikipedia.org/wiki/C_(programming_language) C¬/¬http://en.wikipedia.org/wiki/C++ C++¬
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   125
        or ¬http://www.python.org Python¬. Why should they use a
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   126
        ¬http://en.wikipedia.org/wiki/Functional_programming functional¬ language?
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   127
        >>
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   128
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   129
    p   >>
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   130
        Actually, if a functional language is practical or not, depends of what's to do – “the
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   131
        right tool for the task”, one could say.
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   132
        >>
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   133
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   134
    p   >>
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   135
        Because processing XML data means traversing a (document) tree,
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   136
        ¬http://en.wikipedia.org/wiki/Recursion recursive¬ algorithms are a clear advantage.
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   137
        And this is the reason, why choosing a functional language is a good choice for that job.
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   138
        >>
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   139
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   140
    p   >>
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   141
        It's a little bit like with ¬http://en.wikipedia.org/wiki/SQL SQL¬ – for it's job, it's
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   142
        excellent, but no-one wants to write a complete application in SQL (and also not in one
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   143
        of the Turing-complete SQL extension languages like
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   144
        ¬http://www.oracle.com/technology/tech/pl_sql/index.html PL/SQL¬).
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   145
        >>
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   146
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   147
    h3 id=htmlgen > Generating HTML out of a DSL
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   148
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   149
    p   >>
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   150
        Of course, you can use YSLT as you would use XSLT. Let's say, you have data in XML
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   151
        documents, and you want to have an excerpt out of this data. This is a common task,
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   152
        comparable to «SELECT» data out of an SQL database. But we have no database, we have
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   153
        something like this file customers.yml2:
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   154
        >>
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   155
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   156
    Code    ||
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   157
            decl customer(*id, *name) { id *id, name *name };
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   158
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   159
            list {
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   160
                customer 23, "Kurt Meier";
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   161
                customer 42, "Lieschen Schmidt";
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   162
            }
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   163
            ||
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   164
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   165
    p   >>
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   166
        Let's say, we want to output this into an ¬http://en.wikipedia.org/wiki/XHTML XHTML¬ document,
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   167
        where the list is showed as a table. Then we would do the following:
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   168
        >>
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   169
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   170
    p > The XHTML document should be like the following and include the list in the body:
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   171
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   172
    Code    ||
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   173
            include yslt.yml2
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   174
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   175
            stylesheet {
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   176
                template "/" html {
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   177
                    head title "Customer List";
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   178
                    body apply "list";
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   179
                }
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   180
            ||
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   181
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   182
    p   >>
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   183
        In the example above, stylesheet declares the main program. Then we define a template, which
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   184
        is executed automatically starting reading the root «'/'» of the document tree of the XML
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   185
        document we're processing.
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   186
        >>
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   187
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   188
    p > Using the XML document as input, we're creating this HTML tree:
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   189
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   190
    Code    ||
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   191
            <html>
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   192
                <head>
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   193
                    <title>Customer List</title>
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   194
                </head>
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   195
                <body>
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   196
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   197
                <!-- ... ->
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   198
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   199
                </body>
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   200
            </html>
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   201
            ||
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   202
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   203
    p > How do we create the list? Well, let's use a table with customers:
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   204
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   205
    Code |     template "list" table apply "customer";
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   206
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   207
    p   >>
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   208
        What to do per customer? Well, generate a table row with two columns, one for «id» and one
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   209
        for «name»:
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   210
        >>
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   211
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   212
    Code    ||
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   213
                template "customer" tr {
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   214
                    td value "id";
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   215
                    td value "name";
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   216
                }
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   217
            }
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   218
            ||
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   219
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   220
    p > That was it. We now can run our small program:
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   221
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   222
    Code | % yml2proc -y customer.ysl2 -x customer.xml -o customer.html -P
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   223
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   224
    p > The result looks like this:
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   225
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   226
    Code    ||
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   227
            % cat customer.html 
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   228
            <?xml version="1.0"?>
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   229
            <html>
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   230
              <head>
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   231
                <title>Customer List</title>
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   232
              </head>
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   233
              <body>
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   234
                <table>
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   235
                  <tr>
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   236
                    <td>23</td>
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   237
                    <td>Kurt Meier</td>
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   238
                  </tr>
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   239
                  <tr>
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   240
                    <td>42</td>
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   241
                    <td>Lieschen Schmidt</td>
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   242
                  </tr>
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   243
                </table>
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   244
              </body>
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   245
            </html>
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   246
            % _
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   247
            ||
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   248
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   249
    p > Here you can download ¬samples/customer.ysl2 the complete program¬.
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   250
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   251
    h3 id=codegen > How to generate code with YSLT
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   252
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   253
    p > Generating code is easy with YSLT, if you follow these steps:
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   254
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   255
    ol {
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   256
        li > design the software you want to generate using patterns and write that in a DSL
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   257
        li > write target code once for each pattern
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   258
        li > deconstruct a compiler for the target code for each pattern
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   259
        li > fine tune until the diff is empty
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   260
    }
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   261
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   262
    p   >>
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   263
        Let's test by example. First let's say, we have a pattern of entities we want
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   264
        to implement as Java beans. The enities in our DSL are:
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   265
        >>
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   266
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   267
    Code    ||
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   268
            decl entity +name;
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   269
            decl attr +type +name;
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   270
            decl aggregates +entity;
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   271
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   272
            structure {
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   273
                entity Customer {
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   274
                    attr String name;
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   275
                    attr int creditLimit;
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   276
                    aggregates Order;
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   277
                }
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   278
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   279
                entity Order {
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   280
                    attr String no;
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   281
                    attr String description;
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   282
                    attr int amount;
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   283
                }
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   284
            }
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   285
            ||
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   286
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   287
    p   >>
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   288
        How to write that in a Java Program? Well, following the second step, we're
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   289
        writing our target code manually; for this simple sample, let's be naive and
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   290
        save the following into a file named Customer.java.target:
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   291
        >>
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   292
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   293
    Code    ||
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   294
            import java.util.Vector;
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   295
            import java.util.Collections;
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   296
            import base.Entity;
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   297
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   298
            class Customer extends Entity {
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   299
                Customer {
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   300
                    id = genId();
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   301
                }
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   302
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   303
                // attribute name
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   304
                
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   305
                private String name;
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   306
                public String getName() {
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   307
                    return name;   
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   308
                }
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   309
                public void setName(String value) {
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   310
                    name = value;
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   311
                }
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   312
 
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   313
                // attribute creditLimit
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   314
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   315
                private int creditLimit;
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   316
                public int getCreditLimit() {
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   317
                    return creditLimit;   
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   318
                }
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   319
                public void setCreditLimit(int value) {
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   320
                    creditLimit = value;
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   321
                }
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   322
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   323
                // Order aggregation
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   324
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   325
                protected Vector orderList = new Vector();
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   326
                void addOrder(Order entity) {
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   327
                    orderList.add(entity);
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   328
                }
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   329
                void removeOrder(Order entity) {
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   330
                    orderList.remove(entity);
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   331
                }
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   332
                Iterator orderIterator() {
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   333
                    return orderList.iterator();
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   334
                }
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   335
            }
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   336
            ||
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   337
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   338
    p   >>
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   339
        The third step does most of the work. First we cite this code
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   340
        into gen_entity.ysl2 and create the basic form of an YSLT script:
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   341
        >>
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   342
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   343
    Code    ||
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   344
            include yslt.yml2
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   345
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   346
            tstylesheet {
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   347
                template "/" {
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   348
                    | import java.util.Vector;
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   349
                    | import java.util.Collections;
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   350
                    | import base.Entity;
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   351
                    | 
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   352
                    | class Customer extends Entity {
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   353
                    |     Customer {
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   354
                    |         id = genId();
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   355
                    |     }
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   356
                    | 
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   357
                    |     // attribute name
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   358
                    |     
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   359
                    |     private String name;
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   360
                    |     public String getName() {
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   361
                    |         return name;   
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   362
                    |     }
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   363
                    |     public void setName(String value) {
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   364
                    |         name = value;
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   365
                    |     }
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   366
                    | 
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   367
                    |     // attribute creditLimit
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   368
                    | 
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   369
                    |     private int creditLimit;
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   370
                    |     public int getCreditLimit() {
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   371
                    |         return creditLimit;   
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   372
                    |     }
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   373
                    |     public void setCreditLimit(int value) {
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   374
                    |         creditLimit = value;
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   375
                    |     }
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   376
                    | 
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   377
                    |     // Order aggregation
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   378
                    | 
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   379
                    |     protected Vector orderList = new Vector();
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   380
                    |     void addOrder(Order entity) {
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   381
                    |         orderList.add(entity);
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   382
                    |     }
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   383
                    |     void removeOrder(Order entity) {
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   384
                    |         orderList.remove(entity);
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   385
                    |     }
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   386
                    |     Iterator orderIterator() {
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   387
                    |         return orderList.iterator();
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   388
                    |     }
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   389
                    | }
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   390
                }
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   391
            }
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   392
            ||
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   393
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   394
    p   >>
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   395
        Now for the deconstruction. I think, it'll be best, if we
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   396
        ¬#edocument create a .java file for each entity¬.
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   397
        So we're moving the whole thing into a template for each entity
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   398
        creating a file, and we're applying this for each entity using the name of each
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   399
        Entity as parameter. We're adding some distinction of cases, too.
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   400
        >>
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   401
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   402
    p   >>
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   403
        When we apply, the indention system of YSLT will add an indention level, so we can
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   404
        take out rendundant whitespace; for the first apply we don't want this, so we're
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   405
        giving the number 0 as the indention level.
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   406
        >>
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   407
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   408
    p   >>
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   409
        In attributes, braces «{…}» let us insert the value of an XPath expression into our
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   410
        DSL, while inside quoted text the same is done by the ¬#angledouble angle double quotes¬
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   411
        `] <code>&#xab…&#xbb</code>`:
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   412
        >>
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   413
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   414
    Code    ||
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   415
            include yslt.yml2
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   416
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   417
            tstylesheet {
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   418
                template "/structure" apply "Entity", 0;
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   419
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   420
                template "Entity" document "{@name}.java" {
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   421
                    if "aggregates" {
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   422
                        | import java.util.Vector;
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   423
                        | import java.util.Collections;
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   424
                    }
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   425
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   426
                    | import base.Entity;
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   427
                    | 
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   428
                    | class `] &#xab`@name`] &#xbb` extends Entity {
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   429
                    |     `] &#xab`@name`] &#xbb` {
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   430
                    |         id = genId();
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   431
                    |     }
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   432
                    | 
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   433
            [...]
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   434
                    |         orderList.remove(entity);
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   435
                    |     }
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   436
                    |     Iterator orderIterator() {
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   437
                    |         return orderList.iterator();
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   438
                    |     }
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   439
                    | }
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   440
                }
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   441
            }
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   442
            ||
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   443
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   444
    p   >>
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   445
        Well, not bad. Now for the pattern of an attribute and an aggregation, respectively.
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   446
        >>
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   447
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   448
    Code    ||
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   449
            include yslt.yml2
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   450
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   451
            tstylesheet {
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   452
                template "/structure" apply "Entity";
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   453
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   454
                template "Entity" document "{@name}.java" {
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   455
                    if "aggregates" {
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   456
                        | import java.util.Vector;
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   457
                        | import java.util.Collections;
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   458
                    }
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   459
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   460
                    | import base.Entity;
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   461
                    | 
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   462
                    | class `] &#xab`@name`] &#xbb` extends Entity {
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   463
                    |     `] &#xab`@name`] &#xbb` {
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   464
                    |         id = genId();
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   465
                    |     }
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   466
                    | 
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   467
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   468
                    apply "attr|aggregates";
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   469
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   470
                    | }
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   471
                }
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   472
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   473
                template "attr" {
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   474
                    |
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   475
                    | // attribute `] &#xab`@name`] &#xbb`
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   476
                    |
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   477
                    | private `] &#xab`@type`] &#xbb` `] &#xab`@name`] &#xbb`;
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   478
                    | public `] &#xab`@type`] &#xbb` get`] &#xab`@name`] &#xbb`() {
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   479
                    |     return `] &#xab`@name`] &#xbb`;
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   480
                    | }
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   481
                    | public void set`] &#xab`@name`] &#xbb`(`] &#xab`@type`] &#xbb` value) {
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   482
                    |     `] &#xab`@name`] &#xbb` = value;
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   483
                    | }
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   484
                }
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   485
                
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   486
                template "aggregates" {
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   487
                    |
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   488
                    | // `] &#xab`@entity`] &#xbb` aggregation
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   489
                    | 
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   490
                    | protected Vector `] &#xab`@entity`] &#xbb`List = new Vector();
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   491
                    | void add`] &#xab`@entity`] &#xbb`(`] &#xab`@entity`] &#xbb` entity) {
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   492
                    |     `] &#xab`@entity`] &#xbb`List.add(entity);
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   493
                    | }
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   494
                    | void remove`] &#xab`@entity`] &#xbb`(`] &#xab`@entity`] &#xbb` entity) {
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   495
                    |     `] &#xab`@entity`] &#xbb`List.remove(entity);
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   496
                    | }
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   497
                    | Iterator `] &#xab`@entity`] &#xbb`Iterator() {
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   498
                    |     return `] &#xab`@entity`] &#xbb`List.iterator();
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   499
                    | }
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   500
                }
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   501
            }
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   502
            ||
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   503
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   504
    p   >>
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   505
        As you can see, we're deconstructing step by step. This is a good idea to get
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   506
        into code generation with YSLT, but it remains a good idea even for the advanced
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   507
        programmer: it keeps a clear view on what's happening.
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   508
        >>
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   509
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   510
    p   >>
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   511
        In the last step, test it out and make a diff to your target code. You will see
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   512
        that our example needs some beautifying: in Java, camel case is important and
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   513
        makes you some work to revert characters to uppercase or lowercase, respectively.
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   514
        For that work you'll see that ¬http://www.w3.org/TR/xpath/#function-translate XPath's translate() function¬ is a little bit ugly ;-)
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   515
        So we're defining an ¬features#userop operator¬ for that at the top of the file:
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   516
        >>
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   517
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   518
    Code    ||
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   519
            define operator "“(.*?)”" as call "ucase" with "text", "%1";
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   520
            ||
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   521
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   522
    p   >>
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   523
        Inside the template, we're defining the ucase function:
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   524
        >>
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   525
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   526
    Code    ||
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   527
                function "ucase" {
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   528
                    param "text";
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   529
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   530
                    value "translate(substring($text,1,1),'abcdefghijklmnopqrstuvwxyz','ABCDEFGHIJKLMNOPQRSTUVWXYZ')";
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   531
                    value "substring($text, 2)";
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   532
                }
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   533
            }
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   534
            ||
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   535
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   536
    p   >>
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   537
        Now we can replace one quoting with another; have a look at the getter and setter 
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   538
        methods:
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   539
        >>
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   540
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   541
    Code    ||
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   542
            include yslt.yml2
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   543
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   544
            define operator "“(.*?)”" as call "ucase" with "text", "%1";
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   545
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   546
            tstylesheet {
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   547
                template "/structure" apply "Entity";
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   548
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   549
            [...]
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   550
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   551
                template "attr" {
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   552
                    |
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   553
                    | // attribute `] &#xab`@name`] &#xbb`
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   554
                    |
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   555
                    | private `] &#xab`@type`] &#xbb` `] &#xab`@name`] &#xbb`;
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   556
                    | public `] &#xab`@type`] &#xbb` get“@name”() {
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   557
                    |     return `] &#xab`@name`] &#xbb`;
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   558
                    | }
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   559
                    | public void set“@name”(`] &#xab`@type`] &#xbb` value) {
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   560
                    |     `] &#xab`@name`] &#xbb` = value;
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   561
                    | }
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   562
                }
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   563
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   564
            [...]
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   565
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   566
                function "ucase" {
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   567
                    param "text";
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   568
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   569
                    value "translate(substring($text,1,1),'abcdefghijklmnopqrstuvwxyz','ABCDEFGHIJKLMNOPQRSTUVWXYZ')";
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   570
                    value "substring($text, 2)";
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   571
                }
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   572
            }
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   573
            ||
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   574
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   575
    p   >>
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   576
        Well, the rest is a pure laborious task ;-) Feel free to complete. And: use diff!
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   577
        >>
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   578
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   579
    h3 id=ddlgen > A more advanced example: generating SQL DDL out of an UML diagram
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   580
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   581
    p   >>
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   582
        Well, now for something real ;-) This is a very common task: somebody models
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   583
        with an ¬http://en.wikipedia.org/wiki/Class_diagram UML class diagram¬, and you want
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   584
        to have SQL ¬http://en.wikipedia.org/wiki/Data_Definition_Language DDL¬, which generates
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   585
        a matching database structure.
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   586
        >>
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   587
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   588
    p > Let's go:
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   589
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   590
    p   >>
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   591
        First, lets use a stylesheet, which declares the needed
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   592
        ¬http://www.w3.org/TR/REC-xml-names/ XMI namespaces¬:
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   593
        >>
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   594
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   595
    Code    ||
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   596
            include yslt.yml2
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   597
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   598
            tstylesheet xmlns:uml="http://schema.omg.org/spec/UML/2.1",
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   599
                        xmlns:xmi="http://schema.omg.org/spec/XMI/2.1" {
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   600
            ||
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   601
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   602
    p > Now, search the Model for all content:
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   603
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   604
    Code |    template "/" apply "xmi:XMI/uml:Model/packagedElement", 0;
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   605
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   606
    p   >>
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   607
        We're translating ¬http://en.wikipedia.org/wiki/Package_(UML) UML Packages¬ into
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   608
        underscore separated prefixes:
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   609
        >>
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   610
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   611
    Code    ||
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   612
                template "packagedElement[@xmi:type='uml:Package']" {
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   613
                    param "name", "''";
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   614
                    if "$name=''"  apply "packagedElement", 0 { with "name", "@name"; }
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   615
                    if "$name!=''" apply "packagedElement", 0 { with "name", "concat($name, '_', @name)"; }
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   616
                }
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   617
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   618
            ||
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   619
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   620
    p > Each Class is represented by a table in the database:
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   621
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   622
    Code    ||
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   623
                template "packagedElement[@xmi:type='uml:Class']" {
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   624
                    param "name";
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   625
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   626
                    | CREATE TABLE «$name»_«@name» (
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   627
                    apply "ownedAttribute";
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   628
                    | );
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   629
                }
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   630
            ||
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   631
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   632
    p   >>
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   633
        Finally, for each different data type for an attribute we're outputting different fields
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   634
        with different types:
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   635
        >>
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   636
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   637
    Code    ||
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   638
                template "ownedAttribute[@xmi:type='uml:Property' and type/@xmi:type='uml:PrimitiveType']" {
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   639
                    0> «@name»
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   640
                    choose {
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   641
                        when "type/@href='http://schema.omg.org/spec/UML/2.1/uml.xml#String'"
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   642
                            >  VARCHAR
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   643
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   644
                        // [...] for other types, extend when clauses
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   645
                    }
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   646
                    if "position()!=last()" > ,
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   647
                    text "\\n";
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   648
                }
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   649
            }
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   650
            ||
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   651
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   652
    p > Our little sample only supports «VARCHAR», but it is an easy game to play to complete that.
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   653
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   654
    p   >>
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   655
        Here you can download the ¬samples/xmi2ddl.ysl2 XMI 2 DDL compiler sample¬. I used
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   656
        ¬http://bouml.free.fr/ BOUML¬ to create a small ¬samples/demo.xmi UML sample file¬
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   657
        as ¬http://www.omg.org/spec/XMI/ XMI 2.1¬.
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   658
        >>
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   659
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   660
    p > To compile that, use:
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   661
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   662
    Code    ||
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   663
            % yml2proc -y xmi2ddl.ysl2 -x demo.xmi 
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   664
            CREATE TABLE demo_Customer (
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   665
                id VARCHAR,
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   666
                name VARCHAR
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   667
            );
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   668
            % _
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   669
            ||
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   670
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   671
    p   >>
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   672
        In the samples directory you'll find
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   673
        ¬samples/xmi2ddl.uml2 a prettier solution¬ using ¬samples/uml.yml2 some declares to prettify¬.
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   674
        >>
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   675
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   676
    h1 id=features > Features of YSLT
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   677
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   678
    p   >>
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   679
        Because YSLT just generates XSLT programs, it will be a good idea to read the
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   680
        ¬http://www.w3.org/TR/xslt XSLT Documentation¬ as well as the
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   681
        ¬http://www.w3.org/TR/xpath XPath Documentation¬.
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   682
        >>
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   683
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   684
    p   >>
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   685
        In the following, you find a ¬#functionlist List of YSLT Functions¬ and a
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   686
        ¬#operatorlist List of YSLT Operators¬.
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   687
        >>
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   688
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   689
    h2 id=functionlist > List of YSLT Functions
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   690
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   691
    h3 > apply(select, *indent=1)
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   692
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   693
    p   >>
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   694
        Generates the «<xsl:apply-templates />»
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   695
        ¬http://www.w3.org/TR/xslt#section-Applying-Template-Rules tag¬. The «*indent» pointer gives
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   696
        the number of indention levels to add (default: 1) for the Indention System.
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   697
        >>
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   698
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   699
    p i > Example:
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   700
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   701
    Code | apply "attr|aggregation", mode=define;
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   702
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   703
    h3 id=assert > assert(test, msg)
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   704
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   705
    p   >>
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   706
        Generates «<xsl:value-of select="yml:assert(test, msg)"». See the ¬#ymlassert yml:assert() XPath extension¬.
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   707
        This function does not generate anything when not being called by ¬toolchain#processor ysltproc¬
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   708
        with the --debug switch.
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   709
        >>
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   710
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   711
    h3 > attrib(name, namespace)
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   712
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   713
    p > Generates the «<xsl:attribute />» ¬http://www.w3.org/TR/xslt#creating-attributes tag¬.
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   714
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   715
    h3 > call(name)
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   716
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   717
    p   >>
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   718
        Generates the «<call-template />» ¬http://www.w3.org/TR/xslt#named-templates tag¬.
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   719
        Used to call a «function()».
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   720
        >>
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   721
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   722
    p i > Example:
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   723
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   724
    Code | call "ucase" with "text", "$name";
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   725
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   726
    h3 > choose()
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   727
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   728
    p   >>
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   729
        Generates the «<xsl:choose />»
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   730
        ¬http://www.w3.org/TR/xslt#section-Conditional-Processing-with-xsl:choose tag¬.
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   731
        Use in a «choose() ... when()... otherwise()...» structure.
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   732
        >>
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   733
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   734
    p i > Example:
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   735
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   736
    Code    ||
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   737
            choose {
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   738
                when "$id=1"
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   739
                    > yes
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   740
                when "$id=2"
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   741
                    > no
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   742
                otherwise
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   743
                    error "invalid id";
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   744
            }
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   745
            ||
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   746
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   747
    h3 > comment()
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   748
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   749
    p > Generates the «<xsl:comment />» ¬http://www.w3.org/TR/xslt#section-Creating-Comments tag¬.
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   750
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   751
    p i > Example:
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   752
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   753
    Code | comment "this comment will remain in XML";
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   754
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   755
    h3 > const(name, select)
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   756
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   757
    p > Generates the «<xsl:variable />» ¬http://www.w3.org/TR/xslt#variables tag¬.
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   758
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   759
    p i > Example:
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   760
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   761
    Code | const "pi", 3.14;
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   762
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   763
    h3 > copy(select)
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   764
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   765
    p > Generates the «<xsl:copy-of />» ¬http://www.w3.org/TR/xslt#copy-of tag¬.
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   766
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   767
    p i > Example:
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   768
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   769
    Code | copy ".";
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   770
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   771
    h3 id=debug > debug(msg)
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   772
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   773
    p   >>
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   774
        Generates «<xsl:value-of select="yml:debug(msg)"». See the ¬#ymldebug yml:debug() XPath extension¬.
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   775
        This function does not generate anything when not being called by ¬toolchain#processor ysltproc¬
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   776
        with the --debug switch.
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   777
        >>
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   778
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   779
    h3 > def(name)
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   780
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   781
    p   >>
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   782
        Generates the ¬http://www.exslt.org EXSLT¬ «<func:funcion />»
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   783
        ¬http://www.exslt.org/func/elements/function/ tag¬.
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   784
        >>
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   785
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   786
    h3 id=edocument > document(href, method)
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   787
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   788
    p   >>
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   789
        Generates the ¬http://www.exslt.org EXSLT¬ «<exsl:document />»
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   790
        ¬http://www.exslt.org/exsl/elements/document/ tag¬.
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   791
        >>
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   792
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   793
    p i > Example:
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   794
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   795
    Code    ||
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   796
            template "entity" document "{@name}.java" {
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   797
                […]
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   798
            }
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   799
            ||
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   800
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   801
    h3 > element(name, namespace)
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   802
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   803
    p   >>
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   804
        Generates the «<xsl:element />»
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   805
        ¬http://www.w3.org/TR/xslt#section-Creating-Elements-with-xsl:element tag¬.
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   806
        >>
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   807
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   808
    h3 > error()
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   809
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   810
    p   >>
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   811
        Generates the «<xsl:message />» ¬http://www.w3.org/TR/xslt#message tag¬
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   812
        with attribute «terminate» set to "yes".
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   813
        >>
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   814
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   815
    h3 > estylesheet(*output="xml")
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   816
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   817
    p   >>
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   818
        Does the same as «stylesheet()», but additionally declares the ¬http://www.exslt.org/ EXSLT¬
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   819
        functions of the groups «exsl», «func», «str», «dyn», «set» and «math» and declares the
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   820
        corresponding name spaces.
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   821
        >>
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   822
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   823
    h3 > for(select)
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   824
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   825
    p > Generates the «<xsl:for-each />» ¬http://www.w3.org/TR/xslt#for-each tag¬.
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   826
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   827
    p i > Example:
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   828
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   829
    Code | for "../structure[@name='hello'" > «@type»
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   830
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   831
    h3 > foreach(select)
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   832
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   833
    p > Same as «for()».
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   834
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   835
    h3 > function(name)
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   836
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   837
    p   >>
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   838
        Generates the «<xsl:template />» ¬http://www.w3.org/TR/xslt#named-templates tag¬.
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   839
        Used by calling with «call()».
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   840
        >>
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   841
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   842
    p i > Example:
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   843
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   844
    Code    ||
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   845
            function "ucase" {
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   846
                param "text";
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   847
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   848
                value "translate(substring($text,1,1),'abcdefghijklmnopqrstuvwxyz','ABCDEFGHIJKLMNOPQRSTUVWXYZ')";
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   849
                value "substring($text, 2)";
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   850
            }
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   851
            ||
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   852
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   853
    h3 > if(test)
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   854
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   855
    p   >>
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   856
        Generates the «<xsl:if />»
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   857
        ¬http://www.w3.org/TR/xslt#section-Conditional-Processing-with-xsl:if tag¬.
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   858
        >>
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   859
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   860
    p i > Example:
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   861
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   862
    Code | if "position()<last()" > , 
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   863
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   864
    h3 > import(href)
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   865
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   866
    p > Generates the «<xsl:import />» ¬http://www.w3.org/TR/xslt#import tag¬.
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   867
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   868
    h3 > key(name, match, use)
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   869
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   870
    p > Generates the «<xsl:key />» ¬http://www.w3.org/TR/xslt#key tag¬.
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   871
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   872
    h3 > message()
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   873
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   874
    p > Generates the «<xsl:message />» ¬http://www.w3.org/TR/xslt#message tag¬.
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   875
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   876
    h3 > otherwise()
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   877
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   878
    p   >>
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   879
        Generates the «<xsl:otherwise />»
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   880
        ¬http://www.w3.org/TR/xslt#section-Conditional-Processing-with-xsl:choose tag¬.
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   881
        Use in a «choose() ... when()... otherwise()...» structure.
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   882
        >>
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   883
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   884
    h3 > output(method)
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   885
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   886
    p > Generates the «<xsl:output />» ¬http://www.w3.org/TR/xslt#output tag¬.
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   887
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   888
    h3 > param(name, select)
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   889
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   890
    p > Generates the «<xsl:param />» ¬http://www.w3.org/TR/xslt#variables tag¬.
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   891
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   892
    p i > Example:
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   893
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   894
    Code | param "x", 42;
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   895
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   896
    h3 > processing(name)
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   897
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   898
    p   >>
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   899
        Generates the «<xsl:processing-instruction />»
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   900
        ¬http://www.w3.org/TR/xslt#section-Creating-Processing-Instructions tag¬.
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   901
        >>
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   902
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   903
    h3 > raw()
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   904
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   905
    p   >>
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   906
        Generates the «<xsl:text />» ¬http://www.w3.org/TR/xslt#section-Creating-Text tag¬.
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   907
        Sets the attribute «disable-output-escaping» to "yes".
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   908
        >>
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   909
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   910
    h3 > result(select)
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   911
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   912
    p   >>
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   913
        Generates the ¬http://www.exslt.org EXSLT¬ «<func:result />»
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   914
        ¬http://www.exslt.org/func/elements/result/ tag¬.
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   915
        >>
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   916
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   917
    h3 > stylesheet(*output="xml")
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   918
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   919
    p   >>
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   920
        Generates the XSLT «<stylesheet />» ¬http://www.w3.org/TR/xslt#stylesheet-element tag¬.
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   921
        Additionally generates an «<output />» ¬http://www.w3.org/TR/xslt#output tag¬
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   922
        in the body, with attribute «method» set to the value of the pointer «*output» (default: "xml").
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   923
        >>
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   924
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   925
    p > The content you're giving is placed in the body after the «<output />» tag.
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   926
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   927
    p > The «version» attribute is set to "1.0" and XML namespace «xsl» is correctly defined.
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   928
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   929
    p   >>
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   930
        In short: use for a stylesheet, just give the output type as parameter, if you don't want to
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   931
        to generate XML but HTML ("html") oder plain text ("text").
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   932
        >>
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   933
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   934
    p > «stylesheet()» additionally generates tags for the Indention System.
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   935
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   936
    h3 > template(match)
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   937
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   938
    p   >>
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   939
        Generates the «<xsl:template />» ¬http://www.w3.org/TR/xslt#section-Defining-Template-Rules tag¬.
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   940
        Additionally generates tags for the Indention System.
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   941
        >>
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   942
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   943
    p i > Example:
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   944
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   945
    Code    ||
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   946
            template "attr", mode=declare
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   947
                | attribute `] &#xab@type&#xbb` `] &#xab@name&#xbb`;
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   948
            ||
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   949
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   950
    h3 > text()
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   951
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   952
    p > Generate the «<xsl:text />» ¬http://www.w3.org/TR/xslt#section-Creating-Text tag¬.
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   953
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   954
    h3 > textstylesheet()
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   955
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   956
    p > Same as «estylesheet()», but «*output» is now "text", that means the stylesheet outputs plain text.
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   957
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   958
    h3 > tstylesheet()
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   959
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   960
    p > Same as «textstylesheet()».
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   961
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   962
    h3 > value(select)
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   963
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   964
    p > Generates the «<xsl:value-of />» ¬http://www.w3.org/TR/xslt#value-of tag¬.
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   965
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   966
    p i > Example:
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   967
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   968
    Code | value "@name";
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   969
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   970
    h3 > warning()
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   971
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   972
    p   >>
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   973
        Generates the «<xsl:message />» ¬http://www.w3.org/TR/xslt#message tag¬
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   974
        with attribute «terminate» set to "no".
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   975
        >>
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   976
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   977
    h3 > when()
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   978
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   979
    p   >>
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   980
        Generates the «<xsl:when />»
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   981
        ¬http://www.w3.org/TR/xslt#section-Conditional-Processing-with-xsl:choose tag¬.
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   982
        Use in a «choose() ... when()... otherwise()...» structure.
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   983
        >>
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   984
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   985
    h3 > with(name, select)
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   986
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   987
    p   >>
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   988
        Generates the «<xsl:with-param />»
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   989
        ¬http://www.w3.org/TR/xslt#section-Passing-Parameters-to-Templates tag¬.
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   990
        >>
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   991
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   992
    p i > Example:
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   993
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   994
    Code | call "ucase" with "text", "$name";
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   995
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   996
    h2 id=operatorlist > List of YSLT Text Operators
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   997
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   998
    h3 id="angledouble" > Operator `] <code>&#xab…&#xbb</code>`
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
   999
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
  1000
    p > Generate YSLT Function Call «value('…')».
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
  1001
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
  1002
    h2 id=xpathext > Debugging Functions
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
  1003
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
  1004
    p   >>
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
  1005
        YML defines two functions in namespace http://fdik.org/yml, which are enabled if the command line
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
  1006
        option --debug is given in ¬yslt#processor yml2proc¬.
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
  1007
        >>
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
  1008
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
  1009
    h3 id=ymlassert > yml:assert(test, msg)
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
  1010
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
  1011
    p   >>
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
  1012
        If XPath expression «test» evaluates to «false()» or to an empty set, XPath expression «msg» is
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
  1013
        printed to stderr; the compilation then aborts with an error.
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
  1014
        >>
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
  1015
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
  1016
    p   >>
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
  1017
        Better don't use it directly, use the ¬#assert assert() YSLT function¬.
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
  1018
        >>
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
  1019
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
  1020
    h3 id=ymldebug > yml:debug(msg)
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
  1021
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
  1022
    p   >>
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
  1023
        Prints XPath expression «msg» to stderr.
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
  1024
        >>
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
  1025
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
  1026
    p   >>
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
  1027
        Better don't use it directly, use the ¬#debug debug() YSLT function¬.
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
  1028
        >>
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
  1029
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
  1030
    h2 id=stdlib > Standard Function Library
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
  1031
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
  1032
    p   >>
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
  1033
        Additionally, you can «include standardlib.ysl2» in the body of your stylesheet.
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
  1034
        Then you'll have these extra functions:
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
  1035
        >>
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
  1036
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
  1037
    h3 id=dec2hex > yml:dec2hex(dec, digits=8)
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
  1038
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
  1039
    p   >>
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
  1040
        Converts number «dec» into a string with a hexadecimal representation filled up to
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
  1041
        «digits» digits. If you're omitting the second parameter, it is set to 8.
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
  1042
        >>
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
  1043
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
  1044
    h3 id=hex2dec > yml:hex2dec(hex)
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
  1045
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
  1046
    p   >>
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
  1047
        Converts the string «hex» consisting of hexadecimal digits into a number.
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
  1048
        >>
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
  1049
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
  1050
    h3 id=lcase > yml:lcase(text)
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
  1051
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
  1052
    p   >>
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
  1053
        Converts all uppercase letters of string «text» into lowercase ones.
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
  1054
        >>
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
  1055
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
  1056
    h3 id=ucase > yml:ucase(text)
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
  1057
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
  1058
    p   >>
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
  1059
        Converts all lowercase letters of string «text» into uppercase ones.
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
  1060
        >>
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
  1061
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
  1062
    div id=bottom {
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
  1063
        a href="features" "<< back to YML Features" " "
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
  1064
        a href="#top" "^Top^" " "
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
  1065
        a href="toolchain" "> > explain the Tool Chain" " "
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
  1066
        a href="yslt.en.yhtml2" "(source)"
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
  1067
    }
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
  1068
}
76005e62091d initial commit
Volker Birk <vb@pep-project.org>
parents:
diff changeset
  1069