1
|
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
|
3
|
|
4
|
|
5
|
<!DOCTYPE taglib PUBLIC "-//Sun Microsystems, Inc.//DTD JSP Tag Library 1.1//EN" "http://java.sun.com/j2ee/dtds/web-jsptaglibrary_1_1.dtd">
|
6
|
<taglib>
|
7
|
<tlibversion>1.0</tlibversion>
|
8
|
<jspversion>1.1</jspversion>
|
9
|
<shortname>xtags</shortname>
|
10
|
<uri>http://jakarta.apache.org/taglibs/xtags-1.0</uri>
|
11
|
<info>XTags is a JSP tag library for working with XSLT and XPath.
|
12
|
XTags lets you navigate, process and style XML documents directly in JSP.
|
13
|
XTags makes heavy use of the XPath expression language.
|
14
|
For a good tutorial on XPath you could try the either the
|
15
|
Zvon tutorial or the
|
16
|
specification.
|
17
|
XTags is currently built on top of dom4j the
|
18
|
flexible open source XML framework for the Java platform.
|
19
|
Though increasingly XTags will use a pluggable XPath engine to support
|
20
|
the travesal of DOM and Java Beans too.
|
21
|
To begin with you need to parse an XML document from somewhere.
|
22
|
You can parse a variety of sources of XML documents from local resources,
|
23
|
the output of JSP or external web services.
|
24
|
You can parse the body of the tag
|
25
|
|
26
|
<xtags:parse>
|
27
|
<root>
|
28
|
<child/>
|
29
|
</root>
|
30
|
</xtags:parse>
|
31
|
Or parse an absolute URL via the "url" attribute
|
32
|
|
33
|
<xtags:parse url="http://something.com"/>
|
34
|
You can parse a web app resource using an absolute URI relative to the web-app
|
35
|
context using the "uri" attribute
|
36
|
|
37
|
<xtags:parse uri="/data/foo.xml"/>
|
38
|
Or you can use a URI relative to the the current JSP file
|
39
|
|
40
|
<xtags:parse uri="foo.xml"/>
|
41
|
Then for more complex
|
42
|
requirements such as parsing the output of a piece of JSP, you can do the following (provided you are using a JSP 1.2 container)
|
43
|
|
44
|
<xtags:parse>
|
45
|
<jsp:include page="foo.jsp"/>
|
46
|
</xtags:parse>
|
47
|
Until then you can use the IO tag library to make these requests such as
|
48
|
|
49
|
<xtags:parse>
|
50
|
<io:request url="/foo.jsp"/>
|
51
|
</xtags:parse>
|
52
|
Though the above would result in a seperate HTTP request which would loose
|
53
|
all page, request and session scope state.
|
54
|
So if it must be in the same request the following should work
|
55
|
though care should be taken to avoid scripting variable clashes
|
56
|
|
57
|
<xtags:parse>
|
58
|
<%@ include file="/foo.jsp" %>
|
59
|
</xtags:parse>
|
60
|
To parse the output of an XML-RPC (or SOAP) call, using the IO taglib
|
61
|
you could do the following.
|
62
|
|
63
|
<xtags:parse>
|
64
|
<io:xmlrpc url="/xmlrpc_echo.jsp">
|
65
|
<io:pipe>
|
66
|
<methodCall>
|
67
|
<methodName>examples.getStateName</methodName>
|
68
|
<params>
|
69
|
<param>
|
70
|
<value><i4>41</i4></value>
|
71
|
</param>
|
72
|
</params>
|
73
|
</methodCall>
|
74
|
</io:pipe>
|
75
|
</io:xmlrpc>
|
76
|
|
77
|
</xtags:parse>
|
78
|
Once you have a document parsed you can navigate around its structure using XPath
|
79
|
expressions in a similar manner to that used in XSLT.Loops are as follows (an optional variable id can be specified to define a
|
80
|
scriptlet expression inside the loop):-
|
81
|
|
82
|
<xtags:forEach select="expression">
|
83
|
...
|
84
|
</xtags:forEach>
|
85
|
Simple conditional branching is:-
|
86
|
|
87
|
<xtags:if test="booeanExpression">
|
88
|
...
|
89
|
</xtags:if>
|
90
|
More complex conditional branching is:-
|
91
|
|
92
|
<xtags:choose>
|
93
|
<xtags:when test="booeanExpression">
|
94
|
...
|
95
|
</xtags:when>
|
96
|
<xtags:when test="booeanExpression2">
|
97
|
...
|
98
|
</xtags:when>
|
99
|
<xtags:otherwise>
|
100
|
...
|
101
|
</xtags:otherwise>
|
102
|
</xtags:choose>
|
103
|
Expression evaluation
|
104
|
|
105
|
<xtags:valueOf select="expression"/>
|
106
|
Defining scriptlet variables
|
107
|
|
108
|
<xtags:variable id="variableName" select="expression"/>
|
109
|
All these tags are very similar to their XSLT equivalents, so anyone who's
|
110
|
done XSLT before should find them familiar.
|
111
|
There's also an <xtags:style> tag which performs complete XSL transform
|
112
|
in one tag.
|
113
|
Accessing JSP scopes from XPathXPath expressions can use variables with the syntax $foo.
|
114
|
XTags binds these variables to either page/request/session/application scope
|
115
|
attributes or request parameters which allows xtags to be used as a
|
116
|
conditional logic scripting language too - even without the existence of XML
|
117
|
documents.
|
118
|
A prefix can be used to denote the exact JSP scope from which a variable comes
|
119
|
from such as $request:foo to denote request scope.
|
120
|
There now follows a full breakdown of all the current JSP scopes
|
121
|
$foomaps to pageContext.findAttribute("foo")$page:foomaps to page scope$request:foomaps to request scope$session:foomaps to session scope$app:foomaps to application scope$param:foomaps to request.getParameter("foo")$initParam:foomaps to request.getInitParameter("foo")$cookie:foomaps to the cookie's value for name foo$header:foomaps to request.getHeader("foo") For example, the following JSP would branch logically based on the value of
|
122
|
the (say) request parameter "param":-
|
123
|
|
124
|
<xtags:choose>
|
125
|
<xtags:when test="$param='a'">
|
126
|
current param is 'a'
|
127
|
</xtags:when>
|
128
|
<xtags:when test="$param='b'">
|
129
|
current param is 'b'
|
130
|
</xtags:when>
|
131
|
<xtags:otherwise>
|
132
|
no valid param selected
|
133
|
</xtags:otherwise>
|
134
|
</xtags:choose>
|
135
|
|
136
|
XTags even supports the <xtags:stylesheet> <xtags:template> and
|
137
|
<xtags:applyTemplates> tags from XSLT too though the body of a template must
|
138
|
be an Action object or a seperate JSP file.
|
139
|
</info>
|
140
|
<tag>
|
141
|
<name>style</name>
|
142
|
<tagclass>org.apache.taglibs.xtags.xslt.StyleTag</tagclass>
|
143
|
<bodycontent>JSP</bodycontent>
|
144
|
<attribute>
|
145
|
<name>document</name>
|
146
|
<required>false</required>
|
147
|
<rtexprvalue>true</rtexprvalue>
|
148
|
</attribute>
|
149
|
<attribute>
|
150
|
<name>xml</name>
|
151
|
<required>false</required>
|
152
|
<rtexprvalue>true</rtexprvalue>
|
153
|
</attribute>
|
154
|
<attribute>
|
155
|
<name>xmlReader</name>
|
156
|
<required>false</required>
|
157
|
<rtexprvalue>true</rtexprvalue>
|
158
|
</attribute>
|
159
|
<attribute>
|
160
|
<name>xmlSource</name>
|
161
|
<required>false</required>
|
162
|
<rtexprvalue>true</rtexprvalue>
|
163
|
</attribute>
|
164
|
<attribute>
|
165
|
<name>xsl</name>
|
166
|
<required>false</required>
|
167
|
<rtexprvalue>true</rtexprvalue>
|
168
|
</attribute>
|
169
|
<attribute>
|
170
|
<name>xslReader</name>
|
171
|
<required>false</required>
|
172
|
<rtexprvalue>true</rtexprvalue>
|
173
|
</attribute>
|
174
|
<attribute>
|
175
|
<name>xslSource</name>
|
176
|
<required>false</required>
|
177
|
<rtexprvalue>true</rtexprvalue>
|
178
|
</attribute>
|
179
|
<attribute>
|
180
|
<name>result</name>
|
181
|
<required>false</required>
|
182
|
<rtexprvalue>true</rtexprvalue>
|
183
|
</attribute>
|
184
|
<attribute>
|
185
|
<name>writer</name>
|
186
|
<required>false</required>
|
187
|
<rtexprvalue>true</rtexprvalue>
|
188
|
</attribute>
|
189
|
<attribute>
|
190
|
<name>outputMethod</name>
|
191
|
<required>false</required>
|
192
|
<rtexprvalue>true</rtexprvalue>
|
193
|
</attribute>
|
194
|
</tag>
|
195
|
<tag>
|
196
|
<name>param</name>
|
197
|
<tagclass>org.apache.taglibs.xtags.xslt.ParamTag</tagclass>
|
198
|
<bodycontent>JSP</bodycontent>
|
199
|
<attribute>
|
200
|
<name>name</name>
|
201
|
<required>true</required>
|
202
|
<rtexprvalue>true</rtexprvalue>
|
203
|
</attribute>
|
204
|
<attribute>
|
205
|
<name>value</name>
|
206
|
<required>false</required>
|
207
|
<rtexprvalue>true</rtexprvalue>
|
208
|
</attribute>
|
209
|
</tag>
|
210
|
<tag>
|
211
|
<name>parse</name>
|
212
|
<tagclass>org.apache.taglibs.xtags.xpath.ParseTag</tagclass>
|
213
|
<teiclass>org.apache.taglibs.xtags.xpath.ParseTagExtraInfo</teiclass>
|
214
|
<bodycontent>JSP</bodycontent>
|
215
|
<attribute>
|
216
|
<name>id</name>
|
217
|
<required>false</required>
|
218
|
<rtexprvalue>false</rtexprvalue>
|
219
|
</attribute>
|
220
|
<attribute>
|
221
|
<name>uri</name>
|
222
|
<required>false</required>
|
223
|
<rtexprvalue>true</rtexprvalue>
|
224
|
</attribute>
|
225
|
<attribute>
|
226
|
<name>url</name>
|
227
|
<required>false</required>
|
228
|
<rtexprvalue>true</rtexprvalue>
|
229
|
</attribute>
|
230
|
<attribute>
|
231
|
<name>reader</name>
|
232
|
<required>false</required>
|
233
|
<rtexprvalue>true</rtexprvalue>
|
234
|
</attribute>
|
235
|
<attribute>
|
236
|
<name>validate</name>
|
237
|
<required>false</required>
|
238
|
<rtexprvalue>true</rtexprvalue>
|
239
|
</attribute>
|
240
|
</tag>
|
241
|
<tag>
|
242
|
<name>valueOf</name>
|
243
|
<tagclass>org.apache.taglibs.xtags.xpath.ValueOfTag</tagclass>
|
244
|
<bodycontent>empty</bodycontent>
|
245
|
<attribute>
|
246
|
<name>select</name>
|
247
|
<required>true</required>
|
248
|
<rtexprvalue>true</rtexprvalue>
|
249
|
</attribute>
|
250
|
<attribute>
|
251
|
<name>context</name>
|
252
|
<required>false</required>
|
253
|
<rtexprvalue>true</rtexprvalue>
|
254
|
</attribute>
|
255
|
</tag>
|
256
|
<tag>
|
257
|
<name>forEach</name>
|
258
|
<tagclass>org.apache.taglibs.xtags.xpath.ForEachTag</tagclass>
|
259
|
<teiclass>org.apache.taglibs.xtags.xpath.ForEachTagExtraInfo</teiclass>
|
260
|
<bodycontent>JSP</bodycontent>
|
261
|
<attribute>
|
262
|
<name>select</name>
|
263
|
<required>true</required>
|
264
|
<rtexprvalue>true</rtexprvalue>
|
265
|
</attribute>
|
266
|
<attribute>
|
267
|
<name>sort</name>
|
268
|
<required>false</required>
|
269
|
<rtexprvalue>true</rtexprvalue>
|
270
|
</attribute>
|
271
|
<attribute>
|
272
|
<name>distinct</name>
|
273
|
<required>false</required>
|
274
|
<rtexprvalue>true</rtexprvalue>
|
275
|
</attribute>
|
276
|
<attribute>
|
277
|
<name>ascending</name>
|
278
|
<required>false</required>
|
279
|
<rtexprvalue>true</rtexprvalue>
|
280
|
</attribute>
|
281
|
<attribute>
|
282
|
<name>context</name>
|
283
|
<required>false</required>
|
284
|
<rtexprvalue>true</rtexprvalue>
|
285
|
</attribute>
|
286
|
<attribute>
|
287
|
<name>id</name>
|
288
|
<required>false</required>
|
289
|
<rtexprvalue>false</rtexprvalue>
|
290
|
</attribute>
|
291
|
<attribute>
|
292
|
<name>type</name>
|
293
|
<required>false</required>
|
294
|
<rtexprvalue>false</rtexprvalue>
|
295
|
</attribute>
|
296
|
</tag>
|
297
|
<tag>
|
298
|
<name>choose</name>
|
299
|
<tagclass>org.apache.taglibs.xtags.xpath.ChooseTag</tagclass>
|
300
|
<bodycontent>JSP</bodycontent>
|
301
|
</tag>
|
302
|
<tag>
|
303
|
<name>when</name>
|
304
|
<tagclass>org.apache.taglibs.xtags.xpath.WhenTag</tagclass>
|
305
|
<bodycontent>JSP</bodycontent>
|
306
|
<attribute>
|
307
|
<name>test</name>
|
308
|
<required>true</required>
|
309
|
<rtexprvalue>true</rtexprvalue>
|
310
|
</attribute>
|
311
|
<attribute>
|
312
|
<name>context</name>
|
313
|
<required>false</required>
|
314
|
<rtexprvalue>true</rtexprvalue>
|
315
|
</attribute>
|
316
|
</tag>
|
317
|
<tag>
|
318
|
<name>otherwise</name>
|
319
|
<tagclass>org.apache.taglibs.xtags.xpath.OtherwiseTag</tagclass>
|
320
|
<bodycontent>JSP</bodycontent>
|
321
|
</tag>
|
322
|
<tag>
|
323
|
<name>break</name>
|
324
|
<tagclass>org.apache.taglibs.xtags.xpath.BreakTag</tagclass>
|
325
|
<bodycontent>empty</bodycontent>
|
326
|
</tag>
|
327
|
<tag>
|
328
|
<name>if</name>
|
329
|
<tagclass>org.apache.taglibs.xtags.xpath.IfTag</tagclass>
|
330
|
<bodycontent>JSP</bodycontent>
|
331
|
<attribute>
|
332
|
<name>test</name>
|
333
|
<required>true</required>
|
334
|
<rtexprvalue>true</rtexprvalue>
|
335
|
</attribute>
|
336
|
<attribute>
|
337
|
<name>context</name>
|
338
|
<required>false</required>
|
339
|
<rtexprvalue>true</rtexprvalue>
|
340
|
</attribute>
|
341
|
</tag>
|
342
|
<tag>
|
343
|
<name>variable</name>
|
344
|
<tagclass>org.apache.taglibs.xtags.xpath.VariableTag</tagclass>
|
345
|
<teiclass>org.apache.taglibs.xtags.xpath.VariableTagExtraInfo</teiclass>
|
346
|
<bodycontent>empty</bodycontent>
|
347
|
<attribute>
|
348
|
<name>id</name>
|
349
|
<required>true</required>
|
350
|
<rtexprvalue>false</rtexprvalue>
|
351
|
</attribute>
|
352
|
<attribute>
|
353
|
<name>type</name>
|
354
|
<required>false</required>
|
355
|
<rtexprvalue>false</rtexprvalue>
|
356
|
</attribute>
|
357
|
<attribute>
|
358
|
<name>select</name>
|
359
|
<required>true</required>
|
360
|
<rtexprvalue>true</rtexprvalue>
|
361
|
</attribute>
|
362
|
<attribute>
|
363
|
<name>context</name>
|
364
|
<required>false</required>
|
365
|
<rtexprvalue>true</rtexprvalue>
|
366
|
</attribute>
|
367
|
</tag>
|
368
|
<tag>
|
369
|
<name>stylesheet</name>
|
370
|
<tagclass>org.apache.taglibs.xtags.xpath.StylesheetTag</tagclass>
|
371
|
<bodycontent>JSP</bodycontent>
|
372
|
<attribute>
|
373
|
<name>context</name>
|
374
|
<required>false</required>
|
375
|
<rtexprvalue>true</rtexprvalue>
|
376
|
</attribute>
|
377
|
</tag>
|
378
|
<tag>
|
379
|
<name>template</name>
|
380
|
<tagclass>org.apache.taglibs.xtags.xpath.TemplateTag</tagclass>
|
381
|
<bodycontent>JSP</bodycontent>
|
382
|
<attribute>
|
383
|
<name>match</name>
|
384
|
<required>true</required>
|
385
|
<rtexprvalue>true</rtexprvalue>
|
386
|
</attribute>
|
387
|
<attribute>
|
388
|
<name>mode</name>
|
389
|
<required>false</required>
|
390
|
<rtexprvalue>true</rtexprvalue>
|
391
|
</attribute>
|
392
|
<attribute>
|
393
|
<name>avt</name>
|
394
|
<required>false</required>
|
395
|
<rtexprvalue>true</rtexprvalue>
|
396
|
</attribute>
|
397
|
<attribute>
|
398
|
<name>action</name>
|
399
|
<required>false</required>
|
400
|
<rtexprvalue>true</rtexprvalue>
|
401
|
</attribute>
|
402
|
</tag>
|
403
|
<tag>
|
404
|
<name>applyTemplates</name>
|
405
|
<tagclass>org.apache.taglibs.xtags.xpath.ApplyTemplatesTag</tagclass>
|
406
|
<bodycontent>JSP</bodycontent>
|
407
|
<attribute>
|
408
|
<name>select</name>
|
409
|
<required>false</required>
|
410
|
<rtexprvalue>true</rtexprvalue>
|
411
|
</attribute>
|
412
|
<attribute>
|
413
|
<name>mode</name>
|
414
|
<required>false</required>
|
415
|
<rtexprvalue>true</rtexprvalue>
|
416
|
</attribute>
|
417
|
</tag>
|
418
|
<tag>
|
419
|
<name>element</name>
|
420
|
<tagclass>org.apache.taglibs.xtags.xpath.ElementTag</tagclass>
|
421
|
<bodycontent>JSP</bodycontent>
|
422
|
<attribute>
|
423
|
<name>name</name>
|
424
|
<required>true</required>
|
425
|
<rtexprvalue>true</rtexprvalue>
|
426
|
</attribute>
|
427
|
</tag>
|
428
|
<tag>
|
429
|
<name>attribute</name>
|
430
|
<tagclass>org.apache.taglibs.xtags.xpath.AttributeTag</tagclass>
|
431
|
<bodycontent>JSP</bodycontent>
|
432
|
<attribute>
|
433
|
<name>name</name>
|
434
|
<required>true</required>
|
435
|
<rtexprvalue>true</rtexprvalue>
|
436
|
</attribute>
|
437
|
</tag>
|
438
|
<tag>
|
439
|
<name>output</name>
|
440
|
<tagclass>org.apache.taglibs.xtags.xpath.OutputTag</tagclass>
|
441
|
<bodycontent>JSP</bodycontent>
|
442
|
<attribute>
|
443
|
<name>method</name>
|
444
|
<required>false</required>
|
445
|
<rtexprvalue>true</rtexprvalue>
|
446
|
</attribute>
|
447
|
<attribute>
|
448
|
<name>indent</name>
|
449
|
<required>false</required>
|
450
|
<rtexprvalue>true</rtexprvalue>
|
451
|
</attribute>
|
452
|
<attribute>
|
453
|
<name>omitXmlDeclaration</name>
|
454
|
<required>false</required>
|
455
|
<rtexprvalue>true</rtexprvalue>
|
456
|
</attribute>
|
457
|
</tag>
|
458
|
<tag>
|
459
|
<name>copy</name>
|
460
|
<tagclass>org.apache.taglibs.xtags.xpath.CopyTag</tagclass>
|
461
|
<bodycontent>JSP</bodycontent>
|
462
|
<attribute>
|
463
|
<name>select</name>
|
464
|
<required>true</required>
|
465
|
<rtexprvalue>true</rtexprvalue>
|
466
|
</attribute>
|
467
|
<attribute>
|
468
|
<name>context</name>
|
469
|
<required>false</required>
|
470
|
<rtexprvalue>true</rtexprvalue>
|
471
|
</attribute>
|
472
|
</tag>
|
473
|
<tag>
|
474
|
<name>copyOf</name>
|
475
|
<tagclass>org.apache.taglibs.xtags.xpath.CopyOfTag</tagclass>
|
476
|
<bodycontent>JSP</bodycontent>
|
477
|
<attribute>
|
478
|
<name>select</name>
|
479
|
<required>true</required>
|
480
|
<rtexprvalue>true</rtexprvalue>
|
481
|
</attribute>
|
482
|
<attribute>
|
483
|
<name>context</name>
|
484
|
<required>false</required>
|
485
|
<rtexprvalue>true</rtexprvalue>
|
486
|
</attribute>
|
487
|
</tag>
|
488
|
<tag>
|
489
|
<name>context</name>
|
490
|
<tagclass>org.apache.taglibs.xtags.xpath.ContextTag</tagclass>
|
491
|
<bodycontent>JSP</bodycontent>
|
492
|
<attribute>
|
493
|
<name>select</name>
|
494
|
<required>true</required>
|
495
|
<rtexprvalue>true</rtexprvalue>
|
496
|
</attribute>
|
497
|
<attribute>
|
498
|
<name>context</name>
|
499
|
<required>false</required>
|
500
|
<rtexprvalue>true</rtexprvalue>
|
501
|
</attribute>
|
502
|
</tag>
|
503
|
<tag>
|
504
|
<name>remove</name>
|
505
|
<tagclass>org.apache.taglibs.xtags.xpath.RemoveTag</tagclass>
|
506
|
<bodycontent>empty</bodycontent>
|
507
|
<attribute>
|
508
|
<name>select</name>
|
509
|
<required>true</required>
|
510
|
<rtexprvalue>true</rtexprvalue>
|
511
|
</attribute>
|
512
|
</tag>
|
513
|
<tag>
|
514
|
<name>add</name>
|
515
|
<tagclass>org.apache.taglibs.xtags.xpath.AddTag</tagclass>
|
516
|
<bodycontent>jsp</bodycontent>
|
517
|
<attribute>
|
518
|
<name>before</name>
|
519
|
<required>false</required>
|
520
|
<rtexprvalue>true</rtexprvalue>
|
521
|
</attribute>
|
522
|
<attribute>
|
523
|
<name>after</name>
|
524
|
<required>false</required>
|
525
|
<rtexprvalue>true</rtexprvalue>
|
526
|
</attribute>
|
527
|
</tag>
|
528
|
<tag>
|
529
|
<name>replace</name>
|
530
|
<tagclass>org.apache.taglibs.xtags.xpath.ReplaceTag</tagclass>
|
531
|
<bodycontent>jsp</bodycontent>
|
532
|
</tag>
|
533
|
</taglib>
|
534
|
|
535
|
|
536
|
|
537
|
|
538
|
|
539
|
|
540
|
|
541
|
|
542
|
|
543
|
|
544
|
|
545
|
|
546
|
|
547
|
|
548
|
|
549
|
|
550
|
|
551
|
|
552
|
|
553
|
|
554
|
|
555
|
|