File: xt.htm

package info (click to toggle)
lib-xt-java 0.19990725-1
  • links: PTS
  • area: main
  • in suites: potato
  • size: 1,224 kB
  • ctags: 2,133
  • sloc: java: 9,665; makefile: 54; xml: 28
file content (260 lines) | stat: -rw-r--r-- 9,362 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"
"http://www.w3.org/TR/REC-html40/loose.dtd">
<html>
<head>
<title>XT</title>
</head>
<body>
<h1>XT</h1>
<h2>Version 19990725</h2>

<p>Copyright (c) 1998, 1999 James Clark</p>

<p>See the file <a href="copying.txt">copying.txt</a> for copying
permission.</p>

<p>XT is an implementation in Java of <a
href="http://www.w3.org/TR/1999/WD-xslt-19990709">XSL
Transformations</a>.  This version of XT implements the
WD-xslt-19990709 version of XSLT.  Stylesheets written for earlier
versions of the XSLT WD must be converted before they can be used with
this version of XT.</p>

<p>This should be considered a beta release.</p>

<h2><a name="usage">Usage</a></h2>

<p>To use XT, you need:</p>

<ul>

<li><a href="ftp://ftp.jclark.com/pub/xml/xt.zip">the XT distribution</a></li>

<li>an XML parser in Java that supports <a
href="http://www.megginson.com/SAX/">SAX</a>, such as <a
href="http://www.jclark.com/xml/xp/index.html">XP</a>; you should
choose a SAX parser that provides <code>Locator</code> information,
otherwise you won't get any line numbers in error messages</li>

</ul>

<p>Put <code>xt.jar</code> in your <code>CLASSPATH</code>, together
with whatever is needed for your XML parser, and <code>sax.jar</code>
if that isn't included with your XML parser.  Then use the
command:</p>

<pre>
java -Dcom.jclark.xsl.sax.parser=<var>your-sax-driver</var> com.jclark.xsl.sax.Driver <var>source</var> <var>stylesheet</var> <var>result</var>
</pre>

<p>To find a SAX parser, XT first uses the value of the system
property <code>com.jclark.xsl.sax.parser</code>; if this is not set it
uses the value of the system property <code>org.xml.sax.parser</code>;
if this is not set it uses the class
<code>com.jclark.xml.sax.CommentDriver</code> (This subclasses the
normal XP SAX driver to provide support for comments; it is present
only in XP version 0.5 or later; if you have an earlier version of XP
use <code>-Dcom.jclark.xsl.sax.parser=com.jclark.xml.sax.Driver</code>
instead.)</p>

<p>Alternatively under Windows you can use <a
href="ftp://ftp.jclark.com/pub/xml/xt-win32.zip">XT packaged as a
Win32 executable</a>. This includes XP and SAX.  To use this, you will
need to have the <a
href="http://www.microsoft.com/java/vm/dl_vm32.htm">Microsoft Java
VM</a> installed (this is included with IE).  Run this with the
command:</p>

<pre>
xt <var>source</var> <var>stylesheet</var> <var>result</var>
</pre>

<h2>XT API</h2>

<p>The public interface to XT is
<code>com.jclark.xsl.sax.XSLProcessor</code> which is implemented by
<code>com.jclark.xsl.sax.XSLProcessorImpl</code>.</p>

<h2>Limitations</h2>

<p>The following features of the XSLT WD are not yet implemented:</p>

<ul>

<li>the <code>substring</code> function</li>

<li>the <code>string-length</code> function</li>

<li>attribute sets</li>

<li>the <code>preceding</code> axis</li>

<li>the <code>namespace</code> axis</li>

<li>the <code>xsl:locale</code> element and the optional third
argument on the <code>format-number()</code> function</li>

<li>multiple source documents (the <code>document()</code> function)</li>

<li>keys (the <code>xsl:key</code> element, and the <code>key()</code>
function)</li>

<li>the <code>xsl:message</code> element</li>

<li>the element extension mechanism</li>

<li>the <code>unparsed-entity-uri</code> function</li>

<li>the <code>result-encoding</code> attribute on
<code>xsl:stylesheet</code></li>

<li>the <code>result-version</code> attribute on
<code>xsl:stylesheet</code></li>

</ul>

<p>Error reporting is rather haphazard.  XT does not attempt to
validate stylesheets.  When it detects an error, it either silently
recovers from it, or gives a fatal error.  Forwards-compatible
processing is not yet implemented.</p>

<p>Not much effort has yet been devoted to optimizing performance.
The implementation of some features is known to be slow (notably
<code>xsl:number</code>).</p>

<h2><a name="extension">Extension Functions</a></h2>

<p>A call to a function <code><var>ns</var>:<var>foo</var></code>
where <code><var>ns</var></code> is bound to a namespace of the form
<code>http://www.jclark.com/xt/java/<var>className</var></code> is
treated as a call of the static method <code><var>foo</var></code> of
the class with fully-qualified name
<code><var>className</var></code>. (XT does not currently make use of
the <code>xsl:functions</code> element.)  Hyphens in method names are
removed with the character following the hyphen being upper-cased.
Overloading based on number of parameters is supported; overloading
based on parameter types is not.  A non-static method is treated like
a static method with the <code>this</code> object as an additional
first argument.  A constructor is treated like a static method named
<code>new</code>.  Extension functions can return objects of arbitrary
types which can then be passed as arguments to other extension
functions or stored in variables.</p>

<p>For example, the following</p>

<pre>&lt;xsl:stylesheet
  xmlns:xsl="http://www.w3.org/XSL/Transform/1.0"
  xmlns:date="http://www.jclark.com/xt/java/java.util.Date"
  xmlns="http://www.w3.org/TR/REC-html40"
  result-ns="">

&lt;xsl:template match="/">
  &lt;html>
    &lt;xsl:if test="function-available('date:to-string') and function-available('date:new')">
      &lt;p>&lt;xsl:value-of select="date:to-string(date:new())"/>&lt;/p>
    &lt;/xsl:if>
  &lt;/html>
&lt;/xsl:template>

&lt;/xsl:stylesheet></pre>

<p>will print out the current date.</p>

<p>Types are mapped between XSLT and Java as follows:</p>

<table border="1">
<tr><th>XSLT type</th><th align="left">Java type</th></tr>
<tr><td>string</td><td><code>java.lang.String</code></td>
<tr><td>number</td><td><code>double</code></td></tr>
<tr><td>boolean</td><td><code>boolean</code></td></tr>
<tr><td>node-set</td><td><code>com.jclark.xsl.om.NodeIterator</code></td></tr>
<tr><td>result tree fragment</td><td><code>com.jclark.xsl.sax.ResultTreeFragment</code></td></tr>
</table>

<p>On return from an extension function, an object of type
<code>com.jclark.xsl.om.Node</code> is also allowed and will be
treated node-set; also any numeric type is allowed an will be
converted to a number.</p>

<p>The <code>demo</code> directory has a couple of examples.</p>

<h2><a name="nonxml">Non-XML output</a></h2>

<p>The <code>result-ns</code> attribute can be used to get non-XML
output.  A result namespace of
<code>http://www.w3.org/TR/REC-html40</code> will make XT produce
output that conforms to the HTML 4.0 Recommendation. To use this the
<code>xsl:stylesheet</code> element should look like this:</p>

<pre>&lt;xsl:stylesheet
  xmlns:xsl="http://www.w3.org/XSL/Transform/1.0"
  xmlns="http://www.w3.org/TR/REC-html40"
  result-ns="">
&lt;/xsl:stylesheet></pre>

<p>The result namespace can also use a <code>java:</code> URI.  This
should identify a class that implements the
<code>org.xml.sax.DocumentHandler</code> and
<code>com.jclark.xsl.sax.OutputStreamConverter</code> interfaces.</p>

<p>The <code>com.jclark.xsl.sax.NXMLOutputHandler</code> is one such
class, which is included in XT. This supports a result namespace
which is described by the following DTD:</p>

<pre>&lt;!ELEMENT nxml (escape*, (control|data)*)>
&lt;!ATTLIST nxml encoding NMTOKEN #IMPLIED>
&lt;!ELEMENT escape (#PCDATA|char)*>
&lt;!ATTLIST escape char CDATA #REQUIRED>
&lt;!ELEMENT control (#PCDATA|char|data|control)*>
&lt;!ELEMENT data (#PCDATA|data|control)*>
&lt;!ELEMENT char EMPTY>
&lt;!ATTLIST char number NMTOKEN #REQUIRED></pre>

<p>The <code>nxml</code> element is the root element; the
<code>encoding</code> attribute is the <a
href="http://java.sun.com/products/jdk/1.1/docs/guide/intl/encoding.doc.html"
>name of an encoding supported by your Java VM</a> that will be used
to encode characters as bytes.</p>

<p>The <code>data</code> element contains data.  Within a
<code>data</code> element control characters get escaped.  The
<code>escape</code> element specifies how a particular control
character gets escaped.</p>

<p>The <code>control</code> element contains control information.
Within a <code>control</code> element, all characters are output
directly without escaping.</p>

<p>The <code>char</code> element allows the output of a character that
is not allowed by XML (such as control-L).</p>

<p>For example, the following stylesheet</p>

<pre>&lt;xsl:stylesheet
  xmlns:xsl="http://www.w3.org/XSL/Transform/1.0"
  xmlns="java:com.jclark.xsl.sax.NXMLOutputHandler"
  result-ns="">
&lt;xsl:template match="/">
&lt;nxml>
&lt;escape char="\">\\&lt;/escape>
&lt;data>&amp;amp;&amp;lt;&amp;gt;\&lt;/data>
&lt;control>&amp;amp;&amp;lt;&amp;gt;\&lt;/control>
&lt;/nxml>
&lt;/xsl:template>
&lt;/xsl:stylesheet></pre>

<p>will output</p>

<pre>&amp;&lt;>\\&amp;&lt;>\</pre>

<h2><a name="bug">Reporting Bugs</a></h2>

<p>Please report bugs to me. <strong>When reporting bugs please be
sure to include both a complete stylesheet and complete source
document that illustrate the bug</strong>.</p>

<address>
<a href="mailto:jjc@jclark.com">James Clark</a>
</address>
</body>
</html>