comparison README @ 10:cb41e7c634c5

XSLScript: README and LICENSE.
author Maxim Dounin <mdounin@mdounin.ru>
date Thu, 27 Feb 2014 21:19:33 +0400
parents xslscript.txt@d3340fdeadf6
children
comparison
equal deleted inserted replaced
9:e93b6e98b817 10:cb41e7c634c5
1
2 This code is a replacement for XSLScript, previously available from
3 http://pault.com/pault/XSLScript/. It is not recommended for general
4 use, but rather a replacement for what is used by nginx.
5
6 Snapshot of the original XSLScript documentation is given below,
7 as recovered from:
8
9 http://moemesto.ru/link/6865082
10 http://moemesto.ru/philonov/page/6865082/download/INODE.RU%20/%20ProgrammaZm%20/%20XSLScript%20-%20%D0%B7%D0%B0%D0%BC%D0%B5%D0%BD%D0%B0%20XSLT
11
12 ###############################################################################
13
14 Since Year 2000
15 Version 0.7
16 Check out TerseXML project
17
18 XSLScript is for those, who are writing complex XSLT stylesheets.
19
20 XSLScript is a terse notation for writing complex XSLT stylesheets.
21 XSLScript is part of Hiawatha web-server, but XSLScript also can be
22 used stand-alone.
23
24 To execute XSLScript script:
25
26 xsls some.xml some.xsls
27
28 The XSLScript script (some.xsls) gets compiled into corresponding XSLT
29 stylesheet and then generated XSLT stylesheet is applied to the file
30 some.xml (no temporary .xsl file is created, this all happens in the
31 memory). The actual XSLT tranformation is performed by SAXON. There is
32 1-1 lines mapping between XSLScript script and generated XSLT ( this
33 means if some XSLScript construction starts on line 5, the corresponding
34 XSLT construction will also start on the same line 5. )
35
36 To generate the XSLT stylesheet out of XSLScript script:
37
38 xslsdump some.xsls
39 or
40
41 xslsdump-indent some.xsls
42 if you want a nice looking indentation.
43
44 Why XSLScript ?
45
46 XSLT syntax is not for human beings.
47
48 One can write complex XSLT code in XSLScript and then generate the 100%
49 XSLT stylesheet. Like I do. Occasionaly.
50
51 Can I use my XSLT stylesheets with XSLScript?
52
53 You can use xsl:import / xsl:include to include .xsl into .xsls and to
54 include .xsls into .xsl.
55
56 What if I like writing <xsl:something?
57
58 You can write XSLT instructions in plain XSLT, XSLScript preprocessor
59 will not touch them and will pass those constructions as-is.
60
61 Top-level elements should be plain XSLScript.
62
63 What is XSLScript ?
64
65 XSLScript is just syntax sugar, 1-1 mapping of XSLT. The only exception
66 is that XSLScript has 'else' (which is missing in XSLT). In XSLScript
67 if-else is translated into appropriate xsl:choose-when-otherwise.
68 XSLScript could get more 'non-xslt' semantics if you ask me for
69 something you need.
70
71 OK, but what is XSLScript ?
72
73 Snippet 1
74
75 X:stylesheet {
76
77 X:template = "poem" {
78 <html>
79 <head>
80 <title> !{title} </title>
81 </head>
82 <body>
83 !! "title";
84 !! "author";
85 X:apply-templates "stanza";
86 X:apply-templates "date";
87 </body>
88 </html>
89 }
90
91 X:template = "title" { <div align="center"><h1> !{.} </h1></div> }
92 X:template = "author" { <div align="center"><h2> By <% !{.} %> </h2></div> }
93 X:template = "stanza" { <p> !! "line"; </p> }
94
95 X:template = "line" {
96 X:if "position() mod 2 = 0" {&#160;&#160;}
97 !{.} <br/>
98 }
99
100 X:template = "date" { <p><i> !{.} </i></p> }
101
102 }
103
104
105 Snippet 2
106
107 X:transform {
108
109 X:template max( list ) {
110 X:if "$list" {
111 X:variable first="count($list[1]/LINE)"
112 X:variable max-of-rest={ !max( list="$list[position()!=1]" ) }
113
114 X:if "$first &gt; $max-of-rest" {
115 !{$first}
116 } else {
117 !{$max-of-rest}
118 }
119 } else {
120 0
121 }
122 }
123
124 X:template ="/" {
125 Longest speech is <% X:text; !max( list="//SPEECH" ) X:text; %> lines.
126 }
127
128 }
129
130 Syntax overview
131
132 Rather than drawing the mapping for all of 35 XSLT elements, I'l just
133 provide the mapping rules. If this is not enough, please note that
134 XSLScript distribution contains more than 10 examples of XSLScript code.
135 Those examples are XSLT stylesheets from Michael Kay's XSLT Programming
136 Reference (available for download from Wrox website) rewritten in
137 XSLScript. This results in XSLScript examples being educational and
138 covering almost every XSLT (XSLScript) command.
139
140 Rules
141
142 There are top-level XSLScript constructions and instructions. (exactly
143 like it is in XSLT). Instructions could be separated from the content
144 with <% and %> ( optional ).
145
146 Instruction has body and header. Body is separated from header with { }
147 'match', 'select', 'test' and 'name' are not written (but also could be
148 written in some exotic cases.)
149
150 Symbols ', ", {, are special. Use \{ e t.c. if you need those special
151 symbols in tne content of your stylesheet.
152
153 xsl:apply-templates, !! and xsl:number should end with ";"
154
155 Syntax of apply-templates is extremely close to the syntax of
156 call-template.
157
158 There are few shortcuts:
159 You can use !{xpath-expression} for
160 X:value-of select="xpath-expression";
161 !! for X:apply-templates
162 !foo() for X:call-template name="foo"
163 X:var for X:variable
164
165 There is 'comma' shortcut. It exists for X:stylesheet (see date.xsls for
166 example of XSLT-engine independent java binding). And also it exists for
167 X:for-each and X:apply-templates.
168
169 X:for-each "//*" , X:sort {
170
171 You can not write X:sort as an element, but you should use 'comma'
172 shortcut.
173
174 The shortcut for template allows :
175 X:template foo( bar="init", baz={markup} ) = "match" mode="some" {
176 Download
177
178 Because SAXON (http://users.iclway.co.uk/mhkay/saxon/) is 100% free,
179 XSLScript distribution contains everything you need to run XSLScript.
180
181 xsls.jar includes not only .class files, but also the source code of
182 XSLScript
183
184 XSLScript is 100% free.
185
186 Contact
187
188 Paul Tchistopolskii.
189 http://www.pault.com
190 paul@pault.com
191
192 Changes in version 0.7
193
194 (major rewrite)
195
196 <% %> are optional.
197 Some verbose forms are dropped ( no X:with-param and call-template ever,
198 e t.c. )
199 Parser is less forgiving and some things become not intuitive.
200 \{ \' " required.
201 Nice dumping of generated stylesheet.
202 1-1 line mapping.
203 Based on SAXON / SAX2, but still should work with XT.
204 Changes in version 0.51
205
206 (small bugfixes)
207
208 ':' was not allowed in #NAME token. ( Allows xmlns:some= )
209 Multiple <!-- comments bugfixed.
210 \{ bugfixed and \' allowed. This is actually not obvious, I should
211 explain how to use \{ and \' ... some day ...
212 Few examples from XSL-list are included.
213
214 ###############################################################################