comparison xslscript.txt @ 6:d3340fdeadf6

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