line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# This file was automatically generated from src/xsh_grammar.xml on |
2
|
|
|
|
|
|
|
# Sat Jan 30 02:50:03 2021 |
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
package XML::XSH2::Help; |
5
|
8
|
|
|
8
|
|
52
|
use strict; |
|
8
|
|
|
|
|
14
|
|
|
8
|
|
|
|
|
251
|
|
6
|
8
|
|
|
8
|
|
39
|
use vars qw($HELP %HELP $Apropos); |
|
8
|
|
|
|
|
10
|
|
|
8
|
|
|
|
|
52109
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
$HELP=<<'END'; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
Welcome to XSH help |
12
|
|
|
|
|
|
|
------------------- |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
In this help: |
15
|
|
|
|
|
|
|
[topic] is a cross reference that can be followed using 'help topic' |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
XSH2 acts as a command interpreter. Individual commands must be separated |
18
|
|
|
|
|
|
|
with a semicolon. In the interactive shell, backslash may be used at the |
19
|
|
|
|
|
|
|
end of a line to indicate that a command continues on the next line. |
20
|
|
|
|
|
|
|
Output redirection can be used to pipe output of some XSH [command] to |
21
|
|
|
|
|
|
|
some external program, or to capture the output to a variable. See |
22
|
|
|
|
|
|
|
[Redirection] for more info. |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
XSH2 command [help] provides a complete reference, instantly from the |
25
|
|
|
|
|
|
|
command-line: |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
'help command' gives a list of all XSH2 [commands]. |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
'help type' gives a list of all argument types. |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
'help topic' followed by documentation chapter gives more information on |
32
|
|
|
|
|
|
|
a given topic. |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
'help toc' displays the table of contents. |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
Within the interactive shell, press for auto-completion. |
39
|
|
|
|
|
|
|
END |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
$HELP{'toc'}=[<<'END']; |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
Help items: |
44
|
|
|
|
|
|
|
----------- |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
toc - this page |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
XSH Language Topics: |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
Argtypes - Argument Types |
51
|
|
|
|
|
|
|
Configuration - Global settings |
52
|
|
|
|
|
|
|
Documents - Files/Documents |
53
|
|
|
|
|
|
|
Flow - Flow control |
54
|
|
|
|
|
|
|
Information - Retrieving more information |
55
|
|
|
|
|
|
|
Manipulation - Tree modification |
56
|
|
|
|
|
|
|
Namespaces - Namespaces in XML and XPath |
57
|
|
|
|
|
|
|
Navigation - Tree navigation |
58
|
|
|
|
|
|
|
Perl_shell - Interacting with Perl and Shell |
59
|
|
|
|
|
|
|
Prompt - Prompt in the interactive shell |
60
|
|
|
|
|
|
|
Redirection - Command output redirection |
61
|
|
|
|
|
|
|
Variables - Variables |
62
|
|
|
|
|
|
|
xsh2delta - Changes since XSH 1.x |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
XSH Commands: |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
apropos, assign, backups, call, canonical, catalog, cd, |
67
|
|
|
|
|
|
|
change-ns-prefix, change-ns-uri, clone, close, copy, count, create, |
68
|
|
|
|
|
|
|
debug, declare-ns, def, defs, do, doc-info, documents, dtd, edit, |
69
|
|
|
|
|
|
|
edit-string, empty-tags, enc, encoding, eval, exec, exit, fold, |
70
|
|
|
|
|
|
|
foreach, get, hash, help, if, ifinclude, include, indent, index, |
71
|
|
|
|
|
|
|
insert, iterate, keep-blanks, last, lcd, lineno, load-ext-dtd, local, |
72
|
|
|
|
|
|
|
locate, ls, map, move, my, namespaces, next, nobackups, nodebug, |
73
|
|
|
|
|
|
|
normalize, open, parser-completes-attributes, parser-expands-entities, |
74
|
|
|
|
|
|
|
parser-expands-xinclude, pedantic-parser, perl, prev, print, |
75
|
|
|
|
|
|
|
process-xinclude, pwd, query-encoding, quiet, recovering, redo, |
76
|
|
|
|
|
|
|
register-function, register-namespace, register-xhtml-namespace, |
77
|
|
|
|
|
|
|
register-xsh-namespace, remove, rename, return, run-mode, save, set, |
78
|
|
|
|
|
|
|
set-dtd, set-enc, set-ns, set-standalone, set_filename, settings, |
79
|
|
|
|
|
|
|
skip-dtd, sort, stream, strip-whitespace, switch-to-new-documents, |
80
|
|
|
|
|
|
|
test-mode, throw, try, undef, unfold, unless, unregister-function, |
81
|
|
|
|
|
|
|
unregister-namespace, validate, validation, variables, verbose, |
82
|
|
|
|
|
|
|
version, while, wrap, wrap-span, xcopy, xinsert, xmove, |
83
|
|
|
|
|
|
|
xpath-axis-completion, xpath-completion, xpath-extensions, xslt, |
84
|
|
|
|
|
|
|
xupdate |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
XSH Argument Types: |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
$variable, block, command, document, encoding, expression, filename, |
89
|
|
|
|
|
|
|
location, node-type, nodename, perl-code, subroutine, xpath |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
XPath Extension Functions: |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
xsh:base-uri, xsh:context, xsh:current, xsh:doc, xsh:document, |
94
|
|
|
|
|
|
|
xsh:document-uri, xsh:documents, xsh:evaluate, xsh:filename, xsh:grep, |
95
|
|
|
|
|
|
|
xsh:id2, xsh:if, xsh:join, xsh:lc, xsh:lcfirst, xsh:lineno, xsh:lookup, |
96
|
|
|
|
|
|
|
xsh:map, xsh:match, xsh:matches, xsh:max, xsh:min, xsh:new-attribute, |
97
|
|
|
|
|
|
|
xsh:new-cdata, xsh:new-chunk, xsh:new-comment, xsh:new-element, |
98
|
|
|
|
|
|
|
xsh:new-element-ns, xsh:new-pi, xsh:new-text, xsh:parse, xsh:path, |
99
|
|
|
|
|
|
|
xsh:resolve-uri, xsh:reverse, xsh:same, xsh:serialize, xsh:span, |
100
|
|
|
|
|
|
|
xsh:split, xsh:sprintf, xsh:strmax, xsh:strmin, xsh:subst, xsh:substr, |
101
|
|
|
|
|
|
|
xsh:sum, xsh:times, xsh:uc, xsh:ucfirst, xsh:var |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
END |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
$HELP{'command'}=[<<'END']; |
106
|
|
|
|
|
|
|
command |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
description: |
109
|
|
|
|
|
|
|
XSH2 command consists of a command name and possibly command |
110
|
|
|
|
|
|
|
parameters separated by whitespace. Individual [XSH2 commands] |
111
|
|
|
|
|
|
|
are separated with a semicolon. A command may optionally be |
112
|
|
|
|
|
|
|
followed by an output redirection directive (see |
113
|
|
|
|
|
|
|
[binding_shell] for output redirection to a command and |
114
|
|
|
|
|
|
|
[Variables] for output redirection to variable). Most commands |
115
|
|
|
|
|
|
|
have aliases, so for example [remove] command may also be |
116
|
|
|
|
|
|
|
invoked as 'del' or 'rm'. |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
XSH2 recognizes the following commands (not including |
119
|
|
|
|
|
|
|
aliases): apropos, assign, backups, call, canonical, catalog, |
120
|
|
|
|
|
|
|
cd, change-ns-prefix, change-ns-uri, clone, close, copy, |
121
|
|
|
|
|
|
|
count, create, debug, declare-ns, def, defs, do, doc-info, |
122
|
|
|
|
|
|
|
documents, dtd, edit, edit-string, empty-tags, enc, encoding, |
123
|
|
|
|
|
|
|
eval, exec, exit, fold, foreach, get, hash, help, if, |
124
|
|
|
|
|
|
|
ifinclude, include, indent, index, insert, iterate, |
125
|
|
|
|
|
|
|
keep-blanks, last, lcd, lineno, load-ext-dtd, local, locate, |
126
|
|
|
|
|
|
|
ls, map, move, my, namespaces, next, nobackups, nodebug, |
127
|
|
|
|
|
|
|
normalize, open, parser-completes-attributes, |
128
|
|
|
|
|
|
|
parser-expands-entities, parser-expands-xinclude, |
129
|
|
|
|
|
|
|
pedantic-parser, perl, prev, print, process-xinclude, pwd, |
130
|
|
|
|
|
|
|
query-encoding, quiet, recovering, redo, register-function, |
131
|
|
|
|
|
|
|
register-namespace, register-xhtml-namespace, |
132
|
|
|
|
|
|
|
register-xsh-namespace, remove, rename, return, run-mode, |
133
|
|
|
|
|
|
|
save, set, set-dtd, set-enc, set-ns, set-standalone, |
134
|
|
|
|
|
|
|
set_filename, settings, skip-dtd, sort, stream, |
135
|
|
|
|
|
|
|
strip-whitespace, switch-to-new-documents, test-mode, throw, |
136
|
|
|
|
|
|
|
try, undef, unfold, unless, unregister-function, |
137
|
|
|
|
|
|
|
unregister-namespace, validate, validation, variables, |
138
|
|
|
|
|
|
|
verbose, version, while, wrap, wrap-span, xcopy, xinsert, |
139
|
|
|
|
|
|
|
xmove, xpath-axis-completion, xpath-completion, |
140
|
|
|
|
|
|
|
xpath-extensions, xslt, xupdate |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
see also: block |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
END |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
$HELP{'block'}=[<<'END']; |
148
|
|
|
|
|
|
|
block argument type |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
description: |
151
|
|
|
|
|
|
|
a block of semicolon-separated XSH2 commands enclosed within |
152
|
|
|
|
|
|
|
braces. |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
Example: Count paragraphs in each chapter |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
$i=0; |
157
|
|
|
|
|
|
|
foreach //chapter { |
158
|
|
|
|
|
|
|
$c=count(./para); |
159
|
|
|
|
|
|
|
$i=$i+1; |
160
|
|
|
|
|
|
|
print "$c paragraphs in chapter no.$i"; |
161
|
|
|
|
|
|
|
} |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
END |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
$HELP{'type'}=[<<'END']; |
167
|
|
|
|
|
|
|
List of command argument types |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
description: |
170
|
|
|
|
|
|
|
$variable, block, command, document, encoding, expression, |
171
|
|
|
|
|
|
|
filename, location, node-type, nodename, perl-code, |
172
|
|
|
|
|
|
|
subroutine, xpath |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
END |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
$HELP{'encoding'}=[<<'END']; |
178
|
|
|
|
|
|
|
enc_string argument type |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
description: |
181
|
|
|
|
|
|
|
An [expression] which evaluates to a valid encoding name, e.g. |
182
|
|
|
|
|
|
|
to utf-8, utf-16, iso-8859-1, iso-8859-2, windows-1250 etc. As |
183
|
|
|
|
|
|
|
with [filename], as long as the expression doesn't contain |
184
|
|
|
|
|
|
|
special characters like braces, brackets, quotes, '$', nor |
185
|
|
|
|
|
|
|
'@', it is taken as a literal and evaluates to itself. |
186
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
END |
188
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
$HELP{'$variable'}=[<<'END']; |
191
|
|
|
|
|
|
|
variable name |
192
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
description: |
194
|
|
|
|
|
|
|
Variable names start with a dollar-sign ('$') followed by an |
195
|
|
|
|
|
|
|
identifier. The identifier must match the following regular |
196
|
|
|
|
|
|
|
expression '[a-zA-Z_][a-zA-Z0-9_]*', i.e., it must be at least |
197
|
|
|
|
|
|
|
one character long, must beginning with a letter or |
198
|
|
|
|
|
|
|
underscore, and may only containing letters, underscores, and |
199
|
|
|
|
|
|
|
digits. |
200
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
see also: Variables assign my local |
202
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
END |
204
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
$HELP{'subroutine'}=[<<'END']; |
207
|
|
|
|
|
|
|
sub-routine name |
208
|
|
|
|
|
|
|
|
209
|
|
|
|
|
|
|
description: |
210
|
|
|
|
|
|
|
A sub-routine name is an identifier matching the following |
211
|
|
|
|
|
|
|
regular expression '[a-zA-Z_][a-zA-Z0-9_]*', i.e., it must be |
212
|
|
|
|
|
|
|
at least one character long, must beginning with a letter or |
213
|
|
|
|
|
|
|
underscore, and may only containing letters, underscores, and |
214
|
|
|
|
|
|
|
digits. |
215
|
|
|
|
|
|
|
|
216
|
|
|
|
|
|
|
END |
217
|
|
|
|
|
|
|
|
218
|
|
|
|
|
|
|
|
219
|
|
|
|
|
|
|
$HELP{'document'}=[<<'END']; |
220
|
|
|
|
|
|
|
document |
221
|
|
|
|
|
|
|
|
222
|
|
|
|
|
|
|
description: |
223
|
|
|
|
|
|
|
A document is specified by arbitrary [expression] which |
224
|
|
|
|
|
|
|
evaluates to a non-empty node-list. From this node-list, the |
225
|
|
|
|
|
|
|
first node is taken and its owner document is used. |
226
|
|
|
|
|
|
|
|
227
|
|
|
|
|
|
|
see also: Variables assign my local |
228
|
|
|
|
|
|
|
|
229
|
|
|
|
|
|
|
END |
230
|
|
|
|
|
|
|
|
231
|
|
|
|
|
|
|
|
232
|
|
|
|
|
|
|
$HELP{'filename'}=[<<'END']; |
233
|
|
|
|
|
|
|
Filename argument type |
234
|
|
|
|
|
|
|
|
235
|
|
|
|
|
|
|
description: |
236
|
|
|
|
|
|
|
An [expression] which evaluates to a valid filename or URL. As |
237
|
|
|
|
|
|
|
long as the expression contains no whitespace, no brackets of |
238
|
|
|
|
|
|
|
any type, quotes, double-quotes, '$' character nor '@' |
239
|
|
|
|
|
|
|
character, it is treated as a literal token which evaluates to |
240
|
|
|
|
|
|
|
itself. |
241
|
|
|
|
|
|
|
|
242
|
|
|
|
|
|
|
END |
243
|
|
|
|
|
|
|
|
244
|
|
|
|
|
|
|
|
245
|
|
|
|
|
|
|
$HELP{'nodename'}=[<<'END']; |
246
|
|
|
|
|
|
|
Node-name argument type |
247
|
|
|
|
|
|
|
|
248
|
|
|
|
|
|
|
description: |
249
|
|
|
|
|
|
|
An [expression] which evaluates to a valid name of an element, |
250
|
|
|
|
|
|
|
attribute or processing-instruction node. As long as the |
251
|
|
|
|
|
|
|
expression contains no whitespace, no brackets of any type, |
252
|
|
|
|
|
|
|
quotes, double-quotes, '$' character, nor '@' character, it is |
253
|
|
|
|
|
|
|
treated as a literal token which evaluates to itself. |
254
|
|
|
|
|
|
|
|
255
|
|
|
|
|
|
|
END |
256
|
|
|
|
|
|
|
|
257
|
|
|
|
|
|
|
|
258
|
|
|
|
|
|
|
$HELP{'xpath'}=[<<'END']; |
259
|
|
|
|
|
|
|
XPath argument type |
260
|
|
|
|
|
|
|
|
261
|
|
|
|
|
|
|
description: |
262
|
|
|
|
|
|
|
XSH2 can evaluate XPath expressions as defined in W3C |
263
|
|
|
|
|
|
|
recommendation at http://www.w3.org/TR/xpath with only a |
264
|
|
|
|
|
|
|
little limitation on use of syntactically ignorable |
265
|
|
|
|
|
|
|
whitespace. (Nice interactive XPath tutorials and references |
266
|
|
|
|
|
|
|
can be found at http://www.zvon.org.) |
267
|
|
|
|
|
|
|
|
268
|
|
|
|
|
|
|
In order to allow XSH2 to use white-space as a command |
269
|
|
|
|
|
|
|
argument delimiter (which is far more convenient to type than, |
270
|
|
|
|
|
|
|
say, commas), the use of white-space in XPath is slightly |
271
|
|
|
|
|
|
|
restricted. Thus, in XSH2, white-space can only occur in those |
272
|
|
|
|
|
|
|
parts of an XPath expression, that are surrounded by either |
273
|
|
|
|
|
|
|
brackets, square brackets, single or double quotes. So, for |
274
|
|
|
|
|
|
|
example, otherwise valid XPath expression like |
275
|
|
|
|
|
|
|
|
276
|
|
|
|
|
|
|
/ foo / bar [ @baz = "bar" ] |
277
|
|
|
|
|
|
|
should in XSH2 be written as either of |
278
|
|
|
|
|
|
|
|
279
|
|
|
|
|
|
|
/foo/bar[ @baz = "bar" ] |
280
|
|
|
|
|
|
|
avoiding any white-space outside the square brackets, or |
281
|
|
|
|
|
|
|
completely enclosed in brackets as in |
282
|
|
|
|
|
|
|
|
283
|
|
|
|
|
|
|
( / foo / bar [ @baz = "bar" ] ). |
284
|
|
|
|
|
|
|
XSH2 provides a number of powerful XPath extension functions, |
285
|
|
|
|
|
|
|
listed below and described in separate sections. XPath |
286
|
|
|
|
|
|
|
extension functions by default belong to XSH2 namespace |
287
|
|
|
|
|
|
|
'http://xsh.sourceforge.net/xsh/' with a namespace prefix set |
288
|
|
|
|
|
|
|
to 'xsh'. A program may however call the [xpath-extensions] |
289
|
|
|
|
|
|
|
command to map XSH2 XPath extension functions into the default |
290
|
|
|
|
|
|
|
namespace, so that they may be used directly without any |
291
|
|
|
|
|
|
|
prefix. |
292
|
|
|
|
|
|
|
|
293
|
|
|
|
|
|
|
XPath extension functions defined in XSH2: xsh:base-uri, |
294
|
|
|
|
|
|
|
xsh:context, xsh:current, xsh:doc, xsh:document, |
295
|
|
|
|
|
|
|
xsh:document-uri, xsh:documents, xsh:evaluate, xsh:filename, |
296
|
|
|
|
|
|
|
xsh:grep, xsh:id2, xsh:if, xsh:join, xsh:lc, xsh:lcfirst, |
297
|
|
|
|
|
|
|
xsh:lineno, xsh:lookup, xsh:map, xsh:match, xsh:matches, |
298
|
|
|
|
|
|
|
xsh:max, xsh:min, xsh:new-attribute, xsh:new-cdata, |
299
|
|
|
|
|
|
|
xsh:new-chunk, xsh:new-comment, xsh:new-element, |
300
|
|
|
|
|
|
|
xsh:new-element-ns, xsh:new-pi, xsh:new-text, xsh:parse, |
301
|
|
|
|
|
|
|
xsh:path, xsh:resolve-uri, xsh:reverse, xsh:same, |
302
|
|
|
|
|
|
|
xsh:serialize, xsh:span, xsh:split, xsh:sprintf, xsh:strmax, |
303
|
|
|
|
|
|
|
xsh:strmin, xsh:subst, xsh:substr, xsh:sum, xsh:times, xsh:uc, |
304
|
|
|
|
|
|
|
xsh:ucfirst, xsh:var |
305
|
|
|
|
|
|
|
|
306
|
|
|
|
|
|
|
Example: Open a document and count all sections containing a subsection |
307
|
|
|
|
|
|
|
|
308
|
|
|
|
|
|
|
xsh $scratch/> $v := open mydocument1.xml; |
309
|
|
|
|
|
|
|
xsh $v/> $k := open mydocument2.xml; |
310
|
|
|
|
|
|
|
xsh $k/> count //section[subsection]; # searches k |
311
|
|
|
|
|
|
|
xsh $k/> count $v//section[subsection]; # searches v |
312
|
|
|
|
|
|
|
|
313
|
|
|
|
|
|
|
END |
314
|
|
|
|
|
|
|
|
315
|
|
|
|
|
|
|
|
316
|
|
|
|
|
|
|
$HELP{'expression'}=[<<'END']; |
317
|
|
|
|
|
|
|
expression |
318
|
|
|
|
|
|
|
|
319
|
|
|
|
|
|
|
description: |
320
|
|
|
|
|
|
|
An XSH2 expression can be one of the following constructs: |
321
|
|
|
|
|
|
|
|
322
|
|
|
|
|
|
|
1. XPath 1.0 expression with the following restriction: |
323
|
|
|
|
|
|
|
whitespace is only allowed within parts the expression |
324
|
|
|
|
|
|
|
enclosed in quotes (literal strings) or brackets (XPath has |
325
|
|
|
|
|
|
|
two types of brackets - plain and square). Thus, while '/ |
326
|
|
|
|
|
|
|
foo / bar' is a valid XPath expression matching element |
327
|
|
|
|
|
|
|
named bar under root element foo, in XSH2 this expression |
328
|
|
|
|
|
|
|
must be written as '/foo/bar' or '(/ foo / bar)' or |
329
|
|
|
|
|
|
|
'(/foo/bar)' etc. The reason for this restriction is simple: |
330
|
|
|
|
|
|
|
XSH2, like most shell languages, uses whitespace as argument |
331
|
|
|
|
|
|
|
delimiter so it must be able to determine expression |
332
|
|
|
|
|
|
|
boundaries (otherwise, '/ bar / foo' could be anything |
333
|
|
|
|
|
|
|
between one and four expressions). |
334
|
|
|
|
|
|
|
|
335
|
|
|
|
|
|
|
2. In certain contexts, usually when a filename or a node |
336
|
|
|
|
|
|
|
name is expected as an argument, bareword (otherwise XPath) |
337
|
|
|
|
|
|
|
expressions are evaluated in a non-standard way: as long as |
338
|
|
|
|
|
|
|
the expression contains no whitespace, no brackets of any |
339
|
|
|
|
|
|
|
kind, quotes, double-quotes, '$' character, nor '@' |
340
|
|
|
|
|
|
|
character, it is treated as a literal token which evaluates |
341
|
|
|
|
|
|
|
to itself. This usually happens if a file name or element |
342
|
|
|
|
|
|
|
name is expected, but some other commands, like [print], |
343
|
|
|
|
|
|
|
evaluate its arguments in this way. In order to force an |
344
|
|
|
|
|
|
|
XPath evaluation in such situations, the entire expression |
345
|
|
|
|
|
|
|
should be enclosed with brackets '(...)'. For example, with |
346
|
|
|
|
|
|
|
[open] command, 'open file' or 'open "file"' both open a |
347
|
|
|
|
|
|
|
file whose name is 'file' (literally) whereas 'open (file)' |
348
|
|
|
|
|
|
|
or 'open @file' compute the file name by evaluating '(file)' |
349
|
|
|
|
|
|
|
or '@file' respectively, as XPath expressions. |
350
|
|
|
|
|
|
|
|
351
|
|
|
|
|
|
|
3. Perl blocks. These are enclosed in braces like: '{ |
352
|
|
|
|
|
|
|
perl-code }'. Perl expressions can be used to evaluate more |
353
|
|
|
|
|
|
|
complicated things, like complex string expressions, regexp |
354
|
|
|
|
|
|
|
matches, perl commands, etc. In short, arbitrary perl. Of |
355
|
|
|
|
|
|
|
course, things like '{`ls`}' work too, and that's why we |
356
|
|
|
|
|
|
|
don't need to define shell-like backticks in XSH2 itself. |
357
|
|
|
|
|
|
|
|
358
|
|
|
|
|
|
|
4. Result of one XSH2 command can be directly passed as an |
359
|
|
|
|
|
|
|
argument to another. This is done using &{ xsh-code } |
360
|
|
|
|
|
|
|
expressions. Most XSH2 commands always return 'undef' or 1, |
361
|
|
|
|
|
|
|
but some do return a value, usually a node-list. Examples of |
362
|
|
|
|
|
|
|
such commands are [open], [copy], [move], [wrap], [edit], or |
363
|
|
|
|
|
|
|
[xslt]. |
364
|
|
|
|
|
|
|
|
365
|
|
|
|
|
|
|
5. Large blocks of literal data can be passed to commands |
366
|
|
|
|
|
|
|
via "here document" expressions '<
|
367
|
|
|
|
|
|
|
<<"EOF"'', where 'EOF' is an arbitrary 'ID' string. '<
|
368
|
|
|
|
|
|
|
and '<<"EOF"' are equivalent, and are subject to |
369
|
|
|
|
|
|
|
interpolation of '${...}' constructs, where as '<<'EOF'' |
370
|
|
|
|
|
|
|
does not. The result of evaluation of these three is the |
371
|
|
|
|
|
|
|
literal content (with '${...}' possibly interpolated) of the |
372
|
|
|
|
|
|
|
script starting at the following line and ending at a line |
373
|
|
|
|
|
|
|
containing just 'EOF'. '<<{EOF}' and '<<(EOF)' are |
374
|
|
|
|
|
|
|
implemented too, but I'm not sure they are of any use since |
375
|
|
|
|
|
|
|
putting the expression in ( ) or { } has the same effect. |
376
|
|
|
|
|
|
|
|
377
|
|
|
|
|
|
|
XPath expressions (and their filename variant) are subject to |
378
|
|
|
|
|
|
|
interpolation of substrings of the form '${...}' (called |
379
|
|
|
|
|
|
|
interpolators), where '...' can be of several different forms, |
380
|
|
|
|
|
|
|
described below. The interpolation can be suppressed by |
381
|
|
|
|
|
|
|
preceding the '$' sign with a backslash. |
382
|
|
|
|
|
|
|
|
383
|
|
|
|
|
|
|
Substrings of the form '${id}' or '${$id}' are interpolated |
384
|
|
|
|
|
|
|
with the value of the variable named '$id'. |
385
|
|
|
|
|
|
|
|
386
|
|
|
|
|
|
|
Interpolators of the form '${{' and '}}' evaluate their |
387
|
|
|
|
|
|
|
contents as a Perl expression (in very much the same way as |
388
|
|
|
|
|
|
|
the [perl] command) and interpolate to the resulting value. |
389
|
|
|
|
|
|
|
|
390
|
|
|
|
|
|
|
Interpolators of the form '${(' and ')}' evaluate their |
391
|
|
|
|
|
|
|
contents as an XPath expression and interpolates to a string |
392
|
|
|
|
|
|
|
value of the result. |
393
|
|
|
|
|
|
|
|
394
|
|
|
|
|
|
|
Substrings of the form '\${' interpolate to '${' (as a means |
395
|
|
|
|
|
|
|
for escaping '${...}' in an expression). |
396
|
|
|
|
|
|
|
|
397
|
|
|
|
|
|
|
Expressions are evaluated by XSH2 commands themselves, so the |
398
|
|
|
|
|
|
|
exact value an expression evaluates to, is also |
399
|
|
|
|
|
|
|
command-dependent. There are commands that can handle all data |
400
|
|
|
|
|
|
|
types, but some commands expect their arguments to evaluate |
401
|
|
|
|
|
|
|
only to specific kinds of values. As already mentioned above, |
402
|
|
|
|
|
|
|
commands expecting a filename or a node name usually evaluate |
403
|
|
|
|
|
|
|
simple expressions not containing any special characters as |
404
|
|
|
|
|
|
|
literal strings, whereas commands expecting strings evaluate |
405
|
|
|
|
|
|
|
all expressions so that they get a string value (e.g. by |
406
|
|
|
|
|
|
|
converting a node-set to its text content). Similarly, |
407
|
|
|
|
|
|
|
commands expecting a node-set usually convert strings to a |
408
|
|
|
|
|
|
|
small XML fragments, while commands expecting a single |
409
|
|
|
|
|
|
|
document node usually convert node-sets to a document node by |
410
|
|
|
|
|
|
|
taking the owner document of the first element in the |
411
|
|
|
|
|
|
|
node-set. |
412
|
|
|
|
|
|
|
|
413
|
|
|
|
|
|
|
Example: |
414
|
|
|
|
|
|
|
$a = "bar"; # $a contains: bar |
415
|
|
|
|
|
|
|
$b = $a; # $b contains: bar |
416
|
|
|
|
|
|
|
$b = "$a"; # $b contains: $a |
417
|
|
|
|
|
|
|
$b = "${a}"; # $b contains: bar |
418
|
|
|
|
|
|
|
$b = {$a}; # $b contains: bar |
419
|
|
|
|
|
|
|
$b = //creature; # $b contains a node-set |
420
|
|
|
|
|
|
|
ls $b; # prints the node-set as XML in document order |
421
|
|
|
|
|
|
|
count $b; # prints number of nodes in the node-set |
422
|
|
|
|
|
|
|
echo count($b); # the same |
423
|
|
|
|
|
|
|
$c = string($b[1]/@name) # $c contains string value of //creature[1]/@name (e.g. Bilbo) |
424
|
|
|
|
|
|
|
echo //creature # prints: //creature |
425
|
|
|
|
|
|
|
echo (//creature) # evaluates (//creature) as XPath and prints the |
426
|
|
|
|
|
|
|
# text content of the resulting node-set |
427
|
|
|
|
|
|
|
|
428
|
|
|
|
|
|
|
echo { join(",",split(//,$a)) } # prints: b,a,r |
429
|
|
|
|
|
|
|
echo ${{ join(",",split(//,$a)) }} # the same |
430
|
|
|
|
|
|
|
echo "${{ join(",",split(//,$a)) }}" # the same |
431
|
|
|
|
|
|
|
echo "${(//creature[1]/@name)}" # prints e.g.: Bilbo |
432
|
|
|
|
|
|
|
echo ${(//creature[1]/@name)} # the same |
433
|
|
|
|
|
|
|
echo //creature[1]/@name # the same |
434
|
|
|
|
|
|
|
echo string(//creature[1]/@name) # the same |
435
|
|
|
|
|
|
|
echo (//creature[1]/@name) # the same |
436
|
|
|
|
|
|
|
|
437
|
|
|
|
|
|
|
Example: In-line documents |
438
|
|
|
|
|
|
|
|
439
|
|
|
|
|
|
|
$a="bar" |
440
|
|
|
|
|
|
|
echo foo <
|
441
|
|
|
|
|
|
|
xx ${a} yy |
442
|
|
|
|
|
|
|
END |
443
|
|
|
|
|
|
|
# prints foo xx bar yy baz |
444
|
|
|
|
|
|
|
echo foo <<"END" baz; |
445
|
|
|
|
|
|
|
xx ${a} yy |
446
|
|
|
|
|
|
|
END |
447
|
|
|
|
|
|
|
# same as above |
448
|
|
|
|
|
|
|
echo foo <<'END' baz; |
449
|
|
|
|
|
|
|
xx ${a} yy |
450
|
|
|
|
|
|
|
END |
451
|
|
|
|
|
|
|
# prints foo xx $a yy baz |
452
|
|
|
|
|
|
|
|
453
|
|
|
|
|
|
|
Example: Expressions returning result of a XSH2 command |
454
|
|
|
|
|
|
|
|
455
|
|
|
|
|
|
|
copy &{ sort --key @best_score --numeric //player } into .; |
456
|
|
|
|
|
|
|
|
457
|
|
|
|
|
|
|
END |
458
|
|
|
|
|
|
|
|
459
|
|
|
|
|
|
|
|
460
|
|
|
|
|
|
|
$HELP{'try'}=[<<'END']; |
461
|
|
|
|
|
|
|
usage: try [block] catch [[local|my] [$variable]] [block] |
462
|
|
|
|
|
|
|
|
463
|
|
|
|
|
|
|
description: |
464
|
|
|
|
|
|
|
Execute the [block] following the 'try' keyword. If an error |
465
|
|
|
|
|
|
|
or exception occurs during the evaluation, execute the 'catch' |
466
|
|
|
|
|
|
|
[block]. If the 'catch' keyword is followed by a variable |
467
|
|
|
|
|
|
|
(possibly localized for the following block using [my] or |
468
|
|
|
|
|
|
|
[local]) and the 'try' block fails with an exception, the |
469
|
|
|
|
|
|
|
error message of the exception is stored to the variable |
470
|
|
|
|
|
|
|
before the 'catch' block is executed. |
471
|
|
|
|
|
|
|
|
472
|
|
|
|
|
|
|
The [throw] command as well as an equivalent Perl construction |
473
|
|
|
|
|
|
|
'perl { die "error message" }' allow user to throw custom |
474
|
|
|
|
|
|
|
exceptions. |
475
|
|
|
|
|
|
|
|
476
|
|
|
|
|
|
|
Unless exception is raised or error occurs, this command |
477
|
|
|
|
|
|
|
returns the return value of the 'try' block; otherwise it |
478
|
|
|
|
|
|
|
returns the return value of the 'catch' block. |
479
|
|
|
|
|
|
|
|
480
|
|
|
|
|
|
|
Example: Handle parse errors |
481
|
|
|
|
|
|
|
|
482
|
|
|
|
|
|
|
try { |
483
|
|
|
|
|
|
|
$doc:=open --format xml $input; |
484
|
|
|
|
|
|
|
} catch { |
485
|
|
|
|
|
|
|
try { |
486
|
|
|
|
|
|
|
echo "XML parser failed, trying HTML"; |
487
|
|
|
|
|
|
|
$doc := open --format html $input; |
488
|
|
|
|
|
|
|
} catch my $error { |
489
|
|
|
|
|
|
|
echo "Stopping due to errors: $error"; |
490
|
|
|
|
|
|
|
exit 1; |
491
|
|
|
|
|
|
|
} |
492
|
|
|
|
|
|
|
} |
493
|
|
|
|
|
|
|
|
494
|
|
|
|
|
|
|
see also: throw |
495
|
|
|
|
|
|
|
|
496
|
|
|
|
|
|
|
END |
497
|
|
|
|
|
|
|
|
498
|
|
|
|
|
|
|
|
499
|
|
|
|
|
|
|
$HELP{'if'}=[<<'END']; |
500
|
|
|
|
|
|
|
usage: if [expression] [command] |
501
|
|
|
|
|
|
|
if [expression] |
502
|
|
|
|
|
|
|
[block] [ elsif [block] ]* [ else [block] ] |
503
|
|
|
|
|
|
|
|
504
|
|
|
|
|
|
|
description: |
505
|
|
|
|
|
|
|
Executes [command] or [block] if a given [expression] |
506
|
|
|
|
|
|
|
expression evaluates to a non-emtpty node-list, true |
507
|
|
|
|
|
|
|
boolean-value, non-zero number or non-empty literal. If the |
508
|
|
|
|
|
|
|
first expression fails, then 'elsif' conditions are tested (if |
509
|
|
|
|
|
|
|
any) and the [block] corresponding to the first one of them |
510
|
|
|
|
|
|
|
which is true is executed. If none of the conditions is |
511
|
|
|
|
|
|
|
satisfied, an optional 'else' [block] is executed. |
512
|
|
|
|
|
|
|
|
513
|
|
|
|
|
|
|
Example: Display node type |
514
|
|
|
|
|
|
|
|
515
|
|
|
|
|
|
|
def node_type %n { |
516
|
|
|
|
|
|
|
foreach (%n) { |
517
|
|
|
|
|
|
|
if ( . = self::* ) { # XPath trick to check if . is an element |
518
|
|
|
|
|
|
|
echo 'element'; |
519
|
|
|
|
|
|
|
} elsif ( . = ../@* ) { # XPath trick to check if . is an attribute |
520
|
|
|
|
|
|
|
echo 'attribute'; |
521
|
|
|
|
|
|
|
} elsif ( . = ../processing-instruction() ) { |
522
|
|
|
|
|
|
|
echo 'pi'; |
523
|
|
|
|
|
|
|
} elsif ( . = ../text() ) { |
524
|
|
|
|
|
|
|
echo 'text'; |
525
|
|
|
|
|
|
|
} elsif ( . = ../comment() ) { |
526
|
|
|
|
|
|
|
echo 'comment' |
527
|
|
|
|
|
|
|
} else { # well, this should not happen, but anyway, ... |
528
|
|
|
|
|
|
|
echo 'unknown-type'; |
529
|
|
|
|
|
|
|
} |
530
|
|
|
|
|
|
|
} |
531
|
|
|
|
|
|
|
} |
532
|
|
|
|
|
|
|
|
533
|
|
|
|
|
|
|
Example: Check a environment variable |
534
|
|
|
|
|
|
|
|
535
|
|
|
|
|
|
|
if { defined($ENV{HOME}) } lcd { $ENV{HOME} } |
536
|
|
|
|
|
|
|
|
537
|
|
|
|
|
|
|
END |
538
|
|
|
|
|
|
|
|
539
|
|
|
|
|
|
|
|
540
|
|
|
|
|
|
|
$HELP{'unless'}=[<<'END']; |
541
|
|
|
|
|
|
|
usage: unless [expression] |
542
|
|
|
|
|
|
|
[command] |
543
|
|
|
|
|
|
|
unless [expression] |
544
|
|
|
|
|
|
|
[block] [ else [block] ] |
545
|
|
|
|
|
|
|
|
546
|
|
|
|
|
|
|
description: |
547
|
|
|
|
|
|
|
Like if but negating the result of the expression. Also, |
548
|
|
|
|
|
|
|
unlike if, 'unless' has no 'elsif' block. |
549
|
|
|
|
|
|
|
|
550
|
|
|
|
|
|
|
see also: if |
551
|
|
|
|
|
|
|
|
552
|
|
|
|
|
|
|
END |
553
|
|
|
|
|
|
|
|
554
|
|
|
|
|
|
|
|
555
|
|
|
|
|
|
|
$HELP{'while'}=[<<'END']; |
556
|
|
|
|
|
|
|
usage: while [expression] [block] |
557
|
|
|
|
|
|
|
|
558
|
|
|
|
|
|
|
description: |
559
|
|
|
|
|
|
|
Execute the [command] or [block] as long as the given |
560
|
|
|
|
|
|
|
[expression] evaluates to a non-emtpty node-list, true |
561
|
|
|
|
|
|
|
boolean-value, non-zero number or non-empty literal. |
562
|
|
|
|
|
|
|
|
563
|
|
|
|
|
|
|
Example: The commands in this example do the same thing |
564
|
|
|
|
|
|
|
|
565
|
|
|
|
|
|
|
xsh> while /table/row remove /table/row[1]; |
566
|
|
|
|
|
|
|
xsh> remove /table/row; |
567
|
|
|
|
|
|
|
|
568
|
|
|
|
|
|
|
END |
569
|
|
|
|
|
|
|
|
570
|
|
|
|
|
|
|
|
571
|
|
|
|
|
|
|
$HELP{'do'}=[<<'END']; |
572
|
|
|
|
|
|
|
usage: do [block] |
573
|
|
|
|
|
|
|
|
574
|
|
|
|
|
|
|
description: |
575
|
|
|
|
|
|
|
Execute [block]. This command is probably only useful when one |
576
|
|
|
|
|
|
|
wants to redirect output of more than one command. |
577
|
|
|
|
|
|
|
|
578
|
|
|
|
|
|
|
see also: block |
579
|
|
|
|
|
|
|
|
580
|
|
|
|
|
|
|
END |
581
|
|
|
|
|
|
|
|
582
|
|
|
|
|
|
|
|
583
|
|
|
|
|
|
|
$HELP{'eval'}=[<<'END']; |
584
|
|
|
|
|
|
|
usage: eval [expression] |
585
|
|
|
|
|
|
|
|
586
|
|
|
|
|
|
|
description: |
587
|
|
|
|
|
|
|
NOTE: This command has very different behavior from XSH1, |
588
|
|
|
|
|
|
|
where it used to be an alias for [perl]. |
589
|
|
|
|
|
|
|
|
590
|
|
|
|
|
|
|
This command first evaluates a given [expression] to obtain a |
591
|
|
|
|
|
|
|
string, then evaluates this string as XSH2 code in the current |
592
|
|
|
|
|
|
|
context, returning the return value of the last evaluated |
593
|
|
|
|
|
|
|
command. This command raises an exception if either |
594
|
|
|
|
|
|
|
[expression] evaluates to invalid XSH2 code or if evaluating |
595
|
|
|
|
|
|
|
the code raises an exception. |
596
|
|
|
|
|
|
|
|
597
|
|
|
|
|
|
|
Example: Evaluate "in-line" XSH snippets within a XML document |
598
|
|
|
|
|
|
|
|
599
|
|
|
|
|
|
|
foreach //inline-xsh eval .; |
600
|
|
|
|
|
|
|
|
601
|
|
|
|
|
|
|
END |
602
|
|
|
|
|
|
|
|
603
|
|
|
|
|
|
|
|
604
|
|
|
|
|
|
|
$HELP{'foreach'}=[<<'END']; |
605
|
|
|
|
|
|
|
usage: foreach [expression] |
606
|
|
|
|
|
|
|
[command]|[block] |
607
|
|
|
|
|
|
|
foreach [my|local] [$variable] in [expression] |
608
|
|
|
|
|
|
|
[command]|[block] |
609
|
|
|
|
|
|
|
|
610
|
|
|
|
|
|
|
aliases: for |
611
|
|
|
|
|
|
|
|
612
|
|
|
|
|
|
|
description: |
613
|
|
|
|
|
|
|
Evaluate given [expression] to a node-list and for each |
614
|
|
|
|
|
|
|
resulting node execute given [command] or [block]. If used |
615
|
|
|
|
|
|
|
without a loop [$variable], the loop temporarily sets current |
616
|
|
|
|
|
|
|
node to the node being processed. Otherwise, the processed |
617
|
|
|
|
|
|
|
node is assigned to the loop variable. |
618
|
|
|
|
|
|
|
|
619
|
|
|
|
|
|
|
The [expression] may be [xpath] as well as a [perl-code]. In |
620
|
|
|
|
|
|
|
the latter case, if used without a loop variable, the loop |
621
|
|
|
|
|
|
|
automatically converts Perl objects to nodes. No conversion is |
622
|
|
|
|
|
|
|
performed when a loop variable is used. |
623
|
|
|
|
|
|
|
|
624
|
|
|
|
|
|
|
Example: Move all employee sub-elements in a company element into the |
625
|
|
|
|
|
|
|
first staff subelement of the same company |
626
|
|
|
|
|
|
|
|
627
|
|
|
|
|
|
|
xsh> foreach //company xmove employee into staff[1]; |
628
|
|
|
|
|
|
|
|
629
|
|
|
|
|
|
|
Example: List content of all XML files in current directory |
630
|
|
|
|
|
|
|
|
631
|
|
|
|
|
|
|
xsh> foreach my $filename in { glob('*.xml') } { |
632
|
|
|
|
|
|
|
$f := open $filename; |
633
|
|
|
|
|
|
|
do_something $f; |
634
|
|
|
|
|
|
|
} |
635
|
|
|
|
|
|
|
|
636
|
|
|
|
|
|
|
END |
637
|
|
|
|
|
|
|
|
638
|
|
|
|
|
|
|
$HELP{'for'}=$HELP{'foreach'}; |
639
|
|
|
|
|
|
|
|
640
|
|
|
|
|
|
|
$HELP{'undef'}=[<<'END']; |
641
|
|
|
|
|
|
|
usage: undef [[subroutine] | [$variable]] |
642
|
|
|
|
|
|
|
|
643
|
|
|
|
|
|
|
aliases: undefine |
644
|
|
|
|
|
|
|
|
645
|
|
|
|
|
|
|
description: |
646
|
|
|
|
|
|
|
This command can be used to undefine previously defined XSH2 |
647
|
|
|
|
|
|
|
subroutines and variables. |
648
|
|
|
|
|
|
|
|
649
|
|
|
|
|
|
|
see also: close def |
650
|
|
|
|
|
|
|
|
651
|
|
|
|
|
|
|
END |
652
|
|
|
|
|
|
|
|
653
|
|
|
|
|
|
|
$HELP{'undefine'}=$HELP{'undef'}; |
654
|
|
|
|
|
|
|
|
655
|
|
|
|
|
|
|
$HELP{'def'}=[<<'END']; |
656
|
|
|
|
|
|
|
usage: def [subroutine] [[$variable] ...] [block] |
657
|
|
|
|
|
|
|
|
658
|
|
|
|
|
|
|
aliases: define |
659
|
|
|
|
|
|
|
|
660
|
|
|
|
|
|
|
description: |
661
|
|
|
|
|
|
|
Define a new XSH2 sub-routine named [subroutine]. The |
662
|
|
|
|
|
|
|
subroutine may require zero or more parameters. These are |
663
|
|
|
|
|
|
|
declared as a whitespace-separated list of parametric |
664
|
|
|
|
|
|
|
variables. The body of the subroutine is specified as a |
665
|
|
|
|
|
|
|
[block]. |
666
|
|
|
|
|
|
|
|
667
|
|
|
|
|
|
|
A sub-routine can be invoked directly by its name followed by |
668
|
|
|
|
|
|
|
its arguments just as any XSH2 command, or indirectly using |
669
|
|
|
|
|
|
|
the [call] command followed by an expression evaluating to the |
670
|
|
|
|
|
|
|
routine name and sub-routine arguments. Sub-routine arguments |
671
|
|
|
|
|
|
|
can be arbitrary expressions. These expressions are evaluated |
672
|
|
|
|
|
|
|
prior the sub-routine's code execution and are assigned to the |
673
|
|
|
|
|
|
|
sub-routine's parametric variables in the respective order. |
674
|
|
|
|
|
|
|
The number of parameter variables in a sub-routine definition |
675
|
|
|
|
|
|
|
and the number of arguments in a call to it must match. |
676
|
|
|
|
|
|
|
Calling a sub-routine with less or more arguments than |
677
|
|
|
|
|
|
|
declared is a run-time error. |
678
|
|
|
|
|
|
|
|
679
|
|
|
|
|
|
|
Parametric variables are lexical variables within the |
680
|
|
|
|
|
|
|
sub-routine body as if they were declared with [my]. |
681
|
|
|
|
|
|
|
|
682
|
|
|
|
|
|
|
Note that a subroutine has to be defined before it is first |
683
|
|
|
|
|
|
|
called (in terms of execution -- depending on the structure of |
684
|
|
|
|
|
|
|
the program, the actual definition of the sub-routine must not |
685
|
|
|
|
|
|
|
necessarily precede all references to it). |
686
|
|
|
|
|
|
|
|
687
|
|
|
|
|
|
|
Example: |
688
|
|
|
|
|
|
|
def l3 $nodes { |
689
|
|
|
|
|
|
|
ls --depth 3 $nodes; # list given nodes upto depth 3 |
690
|
|
|
|
|
|
|
} |
691
|
|
|
|
|
|
|
l3 //chapter; # direct call |
692
|
|
|
|
|
|
|
$subref = 'l3'; |
693
|
|
|
|
|
|
|
call $subref //chapter; # in-direct call |
694
|
|
|
|
|
|
|
|
695
|
|
|
|
|
|
|
Example: Commenting and un-commenting pieces of document |
696
|
|
|
|
|
|
|
|
697
|
|
|
|
|
|
|
def comment |
698
|
|
|
|
|
|
|
$n # nodes to move to comments |
699
|
|
|
|
|
|
|
$mark # maybe some handy mark to recognize such comments |
700
|
|
|
|
|
|
|
{ |
701
|
|
|
|
|
|
|
foreach $n { |
702
|
|
|
|
|
|
|
if ( . = ../@* ) { |
703
|
|
|
|
|
|
|
echo "Warning: attribute nodes are not supported!"; |
704
|
|
|
|
|
|
|
} else { |
705
|
|
|
|
|
|
|
echo "Commenting out:"; |
706
|
|
|
|
|
|
|
ls --depth 0 .; |
707
|
|
|
|
|
|
|
add comment concat($mark,xsh:serialize(.)) replace .; |
708
|
|
|
|
|
|
|
} |
709
|
|
|
|
|
|
|
} |
710
|
|
|
|
|
|
|
} |
711
|
|
|
|
|
|
|
|
712
|
|
|
|
|
|
|
def uncomment $n $mark { |
713
|
|
|
|
|
|
|
foreach $n { |
714
|
|
|
|
|
|
|
if (. = ../comment()) { # is this node a comment node |
715
|
|
|
|
|
|
|
local $string = substring-after(.,"$mark"); |
716
|
|
|
|
|
|
|
add chunk $string replace .; |
717
|
|
|
|
|
|
|
} else { |
718
|
|
|
|
|
|
|
echo "Warning: Ignoring non-comment node:"; |
719
|
|
|
|
|
|
|
ls --depth 0 .; |
720
|
|
|
|
|
|
|
} |
721
|
|
|
|
|
|
|
} |
722
|
|
|
|
|
|
|
} |
723
|
|
|
|
|
|
|
|
724
|
|
|
|
|
|
|
# comment out all chapters with no paragraphs |
725
|
|
|
|
|
|
|
comment //chapter[not(para)] "COMMENT-NOPARA"; |
726
|
|
|
|
|
|
|
|
727
|
|
|
|
|
|
|
# uncomment all comments stamped with COMMENT-NOPARA |
728
|
|
|
|
|
|
|
$mark="COMMENT-NOPARA"; |
729
|
|
|
|
|
|
|
uncomment //comment()[starts-with(.,"$mark")] $mark; |
730
|
|
|
|
|
|
|
|
731
|
|
|
|
|
|
|
see also: call return my local |
732
|
|
|
|
|
|
|
|
733
|
|
|
|
|
|
|
END |
734
|
|
|
|
|
|
|
|
735
|
|
|
|
|
|
|
$HELP{'define'}=$HELP{'def'}; |
736
|
|
|
|
|
|
|
|
737
|
|
|
|
|
|
|
$HELP{'assign'}=[<<'END']; |
738
|
|
|
|
|
|
|
usage: [assign] [$variable] = [expression] |
739
|
|
|
|
|
|
|
[assign] [$variable] := [command] |
740
|
|
|
|
|
|
|
[assign] [$variable] [-= | += | *= | /= | %= | x= | .= | ||= | &&= ] [expression] |
741
|
|
|
|
|
|
|
[assign] [$variable] [-:= | +:= | *:= | /:= | %:= | x:= | .:= | ||:= | &&:= ] [command] |
742
|
|
|
|
|
|
|
|
743
|
|
|
|
|
|
|
description: |
744
|
|
|
|
|
|
|
Evaluate the expression (= assignment) or command (:= |
745
|
|
|
|
|
|
|
assignment) on the right side of the assignment and store the |
746
|
|
|
|
|
|
|
result in a given variable. Optionally a Perl operator (- |
747
|
|
|
|
|
|
|
subtraction, + addition, * multiplication, / division, % |
748
|
|
|
|
|
|
|
modulo, x repeat string n-times, . concatenation, || logical |
749
|
|
|
|
|
|
|
OR, && logical AND) can precede the assignment, in which case |
750
|
|
|
|
|
|
|
the variable is assigned the result of applying given operator |
751
|
|
|
|
|
|
|
on its previous value and the value of the right side of the |
752
|
|
|
|
|
|
|
assignment. |
753
|
|
|
|
|
|
|
|
754
|
|
|
|
|
|
|
Example: Assign XPath (node-set, string), or Perl results |
755
|
|
|
|
|
|
|
|
756
|
|
|
|
|
|
|
xsh> $a=chapter/title; |
757
|
|
|
|
|
|
|
xsh> $b="hallo world"; |
758
|
|
|
|
|
|
|
xsh> $c={ `uname` }; |
759
|
|
|
|
|
|
|
xsh> ls $a; |
760
|
|
|
|
|
|
|
|
761
|
|
|
|
|
|
|
Example: Arithmetic expressions (XPath) |
762
|
|
|
|
|
|
|
|
763
|
|
|
|
|
|
|
xsh> $a=5*100 # assign 500 to $a |
764
|
|
|
|
|
|
|
xsh> $a += 20 # add 20 to $a |
765
|
|
|
|
|
|
|
xsh> $a = (($a+5) div 10) |
766
|
|
|
|
|
|
|
|
767
|
|
|
|
|
|
|
Example: Arithmetic expressions (Perl) |
768
|
|
|
|
|
|
|
|
769
|
|
|
|
|
|
|
xsh> $a={ 5*100 } |
770
|
|
|
|
|
|
|
xsh> $a = { join ';', split //,"hallo" } # assigns "h;a;l;l;o" to $a |
771
|
|
|
|
|
|
|
|
772
|
|
|
|
|
|
|
Example: Command result assignment |
773
|
|
|
|
|
|
|
|
774
|
|
|
|
|
|
|
xsh> $doc := open "file.xml" # open a document |
775
|
|
|
|
|
|
|
xsh> $copies := xcopy //foo into //bar # copy elements and store the copies |
776
|
|
|
|
|
|
|
xsh> $wrappers := wrap "wrapper" $copies # wrap each node from $copies to a new element "wrapper" and store the wrapping elements |
777
|
|
|
|
|
|
|
|
778
|
|
|
|
|
|
|
see also: variables |
779
|
|
|
|
|
|
|
|
780
|
|
|
|
|
|
|
END |
781
|
|
|
|
|
|
|
|
782
|
|
|
|
|
|
|
|
783
|
|
|
|
|
|
|
$HELP{'my'}=[<<'END']; |
784
|
|
|
|
|
|
|
usage: my [$variable] [$var2 ...]; |
785
|
|
|
|
|
|
|
my [$variable] = [expression]; |
786
|
|
|
|
|
|
|
|
787
|
|
|
|
|
|
|
description: |
788
|
|
|
|
|
|
|
Same as in Perl: a "my" declares the listed variables to be |
789
|
|
|
|
|
|
|
local (lexically) to the enclosing block, or sub-routine. |
790
|
|
|
|
|
|
|
|
791
|
|
|
|
|
|
|
see also: local |
792
|
|
|
|
|
|
|
|
793
|
|
|
|
|
|
|
END |
794
|
|
|
|
|
|
|
|
795
|
|
|
|
|
|
|
|
796
|
|
|
|
|
|
|
$HELP{'local'}=[<<'END']; |
797
|
|
|
|
|
|
|
usage: local [$variable] = [xpath] |
798
|
|
|
|
|
|
|
local [$variable] [ [$variable] ... ] |
799
|
|
|
|
|
|
|
|
800
|
|
|
|
|
|
|
description: |
801
|
|
|
|
|
|
|
This command acts in a very similar way as [assign] does, |
802
|
|
|
|
|
|
|
except that the variable assignment is done temporarily and |
803
|
|
|
|
|
|
|
lasts only for the rest of its enclosing [block] or |
804
|
|
|
|
|
|
|
subroutine. At the end of the enclosing block or subroutine, |
805
|
|
|
|
|
|
|
the original value is restored. This also reverts any later |
806
|
|
|
|
|
|
|
usual assignments to the variable done occurring before the |
807
|
|
|
|
|
|
|
end of the block. This command may also be used without the |
808
|
|
|
|
|
|
|
assignment part. |
809
|
|
|
|
|
|
|
|
810
|
|
|
|
|
|
|
Note, that the variable itself remains global in the sense |
811
|
|
|
|
|
|
|
that it is still visible to any subroutine called subsequently |
812
|
|
|
|
|
|
|
from the same block. Unlike [my] declaration, it does not |
813
|
|
|
|
|
|
|
create a new lexically scoped variable. |
814
|
|
|
|
|
|
|
|
815
|
|
|
|
|
|
|
Hint for Perl programmers: 'local' in XSH2 works exactly as |
816
|
|
|
|
|
|
|
'local' in Perl. |
817
|
|
|
|
|
|
|
|
818
|
|
|
|
|
|
|
see also: assign my def |
819
|
|
|
|
|
|
|
|
820
|
|
|
|
|
|
|
END |
821
|
|
|
|
|
|
|
|
822
|
|
|
|
|
|
|
|
823
|
|
|
|
|
|
|
$HELP{'settings'}=[<<'END']; |
824
|
|
|
|
|
|
|
usage: settings |
825
|
|
|
|
|
|
|
|
826
|
|
|
|
|
|
|
description: |
827
|
|
|
|
|
|
|
List current values of all XSH2 settings (such as validation |
828
|
|
|
|
|
|
|
flag or query-encoding). |
829
|
|
|
|
|
|
|
|
830
|
|
|
|
|
|
|
'--variables' or ':v' flag enforces syntax which makes use of |
831
|
|
|
|
|
|
|
variable assignments. Otherwise, settings are listed in the |
832
|
|
|
|
|
|
|
form of XSH commands. |
833
|
|
|
|
|
|
|
|
834
|
|
|
|
|
|
|
Example: Store current settings in your .xsh2rc |
835
|
|
|
|
|
|
|
|
836
|
|
|
|
|
|
|
xsh> settings | cat > ~/.xsh2rc |
837
|
|
|
|
|
|
|
|
838
|
|
|
|
|
|
|
END |
839
|
|
|
|
|
|
|
|
840
|
|
|
|
|
|
|
|
841
|
|
|
|
|
|
|
$HELP{'defs'}=[<<'END']; |
842
|
|
|
|
|
|
|
usage: defs |
843
|
|
|
|
|
|
|
|
844
|
|
|
|
|
|
|
description: |
845
|
|
|
|
|
|
|
List names and parametric variables for all user-defined XSH2 |
846
|
|
|
|
|
|
|
subroutines. |
847
|
|
|
|
|
|
|
|
848
|
|
|
|
|
|
|
see also: def variables |
849
|
|
|
|
|
|
|
|
850
|
|
|
|
|
|
|
END |
851
|
|
|
|
|
|
|
|
852
|
|
|
|
|
|
|
|
853
|
|
|
|
|
|
|
$HELP{'ifinclude'}=[<<'END']; |
854
|
|
|
|
|
|
|
usage: ifinclude [--encoding|:e [encoding]] [filename] |
855
|
|
|
|
|
|
|
|
856
|
|
|
|
|
|
|
description: |
857
|
|
|
|
|
|
|
Unless the file [filename] has already been included using |
858
|
|
|
|
|
|
|
either [include] of [ifinclude], load the file and execute it |
859
|
|
|
|
|
|
|
as a XSH2 script. |
860
|
|
|
|
|
|
|
|
861
|
|
|
|
|
|
|
Use '--encoding' or ':e' parameter to specify character |
862
|
|
|
|
|
|
|
encoding used in the included file. |
863
|
|
|
|
|
|
|
|
864
|
|
|
|
|
|
|
see also: include |
865
|
|
|
|
|
|
|
|
866
|
|
|
|
|
|
|
END |
867
|
|
|
|
|
|
|
|
868
|
|
|
|
|
|
|
|
869
|
|
|
|
|
|
|
$HELP{'include'}=[<<'END']; |
870
|
|
|
|
|
|
|
usage: include [--encoding|:e [encoding]] [filename] |
871
|
|
|
|
|
|
|
|
872
|
|
|
|
|
|
|
aliases: . |
873
|
|
|
|
|
|
|
|
874
|
|
|
|
|
|
|
description: |
875
|
|
|
|
|
|
|
Load a file named [filename] and execute it as a XSH2 script. |
876
|
|
|
|
|
|
|
|
877
|
|
|
|
|
|
|
Use '--encoding' or ':e' parameter to specify character |
878
|
|
|
|
|
|
|
encoding used in the included file. |
879
|
|
|
|
|
|
|
|
880
|
|
|
|
|
|
|
see also: ifinclude |
881
|
|
|
|
|
|
|
|
882
|
|
|
|
|
|
|
END |
883
|
|
|
|
|
|
|
|
884
|
|
|
|
|
|
|
$HELP{'.'}=$HELP{'include'}; |
885
|
|
|
|
|
|
|
|
886
|
|
|
|
|
|
|
$HELP{'apropos'}=[<<'END']; |
887
|
|
|
|
|
|
|
usage: apropos [--fulltext] [--regexp] [expression] |
888
|
|
|
|
|
|
|
|
889
|
|
|
|
|
|
|
description: |
890
|
|
|
|
|
|
|
Print all help topics containing given expression in their |
891
|
|
|
|
|
|
|
short description. The '--fulltext' flag forces the search to |
892
|
|
|
|
|
|
|
be performed over the full text of help. '--regexp' indicates, |
893
|
|
|
|
|
|
|
that the given [expression] is a regular expression instead of |
894
|
|
|
|
|
|
|
a literal string. |
895
|
|
|
|
|
|
|
|
896
|
|
|
|
|
|
|
END |
897
|
|
|
|
|
|
|
|
898
|
|
|
|
|
|
|
|
899
|
|
|
|
|
|
|
$HELP{'help'}=[<<'END']; |
900
|
|
|
|
|
|
|
usage: help [command]|argument-type|xsh:xpath-function |
901
|
|
|
|
|
|
|
|
902
|
|
|
|
|
|
|
description: |
903
|
|
|
|
|
|
|
Print help on a given command, argument type or XPath |
904
|
|
|
|
|
|
|
extension function (use 'xsh:' as a prefix to XPath extensions |
905
|
|
|
|
|
|
|
function names, e.g 'help xsh:id2'). |
906
|
|
|
|
|
|
|
|
907
|
|
|
|
|
|
|
END |
908
|
|
|
|
|
|
|
|
909
|
|
|
|
|
|
|
|
910
|
|
|
|
|
|
|
$HELP{'exec'}=[<<'END']; |
911
|
|
|
|
|
|
|
usage: exec [expression] [[expression] ...] |
912
|
|
|
|
|
|
|
|
913
|
|
|
|
|
|
|
aliases: system |
914
|
|
|
|
|
|
|
|
915
|
|
|
|
|
|
|
description: |
916
|
|
|
|
|
|
|
This command executes given [expression](s) as a system |
917
|
|
|
|
|
|
|
command and returns the exit code. |
918
|
|
|
|
|
|
|
|
919
|
|
|
|
|
|
|
Example: Count words in "hallo wold" string, then print name of your |
920
|
|
|
|
|
|
|
machine's operating system. |
921
|
|
|
|
|
|
|
|
922
|
|
|
|
|
|
|
exec echo hallo world; # prints hallo world |
923
|
|
|
|
|
|
|
exec "echo hallo word" | wc; # counts words in hallo world |
924
|
|
|
|
|
|
|
exec uname; # prints operating system name |
925
|
|
|
|
|
|
|
|
926
|
|
|
|
|
|
|
END |
927
|
|
|
|
|
|
|
|
928
|
|
|
|
|
|
|
$HELP{'system'}=$HELP{'exec'}; |
929
|
|
|
|
|
|
|
|
930
|
|
|
|
|
|
|
$HELP{'xslt'}=[<<'END']; |
931
|
|
|
|
|
|
|
usage: $result := xslt [--doc|:d | --precompiled|:p] [--string] [expression] [[document] name=[xpath] [name=[xpath] ...]] |
932
|
|
|
|
|
|
|
$pre_compiled := xslt [--compile|:c] [expression] |
933
|
|
|
|
|
|
|
|
934
|
|
|
|
|
|
|
aliases: transform xsl xsltproc process |
935
|
|
|
|
|
|
|
|
936
|
|
|
|
|
|
|
description: |
937
|
|
|
|
|
|
|
This function compiles a given XSLT stylesheet and/or |
938
|
|
|
|
|
|
|
transforms a given document with XSLT. |
939
|
|
|
|
|
|
|
|
940
|
|
|
|
|
|
|
A XSLT stylesheet is specified in the first argument either as |
941
|
|
|
|
|
|
|
a file name (default), or as a document ('--doc' or ':d'), or |
942
|
|
|
|
|
|
|
as a precompiled XSLT stylesheet object ('--precompiled' or |
943
|
|
|
|
|
|
|
':p' - see '--compile' above). |
944
|
|
|
|
|
|
|
|
945
|
|
|
|
|
|
|
If '--compile' or ':c' is used, compile a given XSLT |
946
|
|
|
|
|
|
|
stylesheet and return a compiled XSLT stylesheet object. This |
947
|
|
|
|
|
|
|
object can be later passed as a XSLT stylesheet to 'xslt |
948
|
|
|
|
|
|
|
--precompiled'. |
949
|
|
|
|
|
|
|
|
950
|
|
|
|
|
|
|
Without '--compile' or ':c', transform a given [document] (or |
951
|
|
|
|
|
|
|
- if used with only the stylesheet argument - the current |
952
|
|
|
|
|
|
|
document) using a given XSLT stylesheet and return the result. |
953
|
|
|
|
|
|
|
|
954
|
|
|
|
|
|
|
All arguments following the second (document) argument are |
955
|
|
|
|
|
|
|
considered to be stylesheet parameters and (after expanding |
956
|
|
|
|
|
|
|
'${...}' interpolators) are directly passed to the XSLT engine |
957
|
|
|
|
|
|
|
without being evaluated by XSH2. All stylesheet parameters |
958
|
|
|
|
|
|
|
should be of the form 'name=[xpath]' (possibly in brackets). |
959
|
|
|
|
|
|
|
|
960
|
|
|
|
|
|
|
Example: Process current document with XSLT |
961
|
|
|
|
|
|
|
|
962
|
|
|
|
|
|
|
$result := xslt stylesheet.xsl . font='14pt' color='red' |
963
|
|
|
|
|
|
|
|
964
|
|
|
|
|
|
|
Example: Same for several documents, reusing the XSLT stylesheet |
965
|
|
|
|
|
|
|
|
966
|
|
|
|
|
|
|
$xslt := xslt --compile stylesheet.xsl; |
967
|
|
|
|
|
|
|
foreach my $file in {qw(f1.xml f2.xml f3.xml)} { |
968
|
|
|
|
|
|
|
save --file {"out_$file"} &{xslt --precompiled $xslt &{ open $file } font='14pt' color='red'}; |
969
|
|
|
|
|
|
|
} |
970
|
|
|
|
|
|
|
|
971
|
|
|
|
|
|
|
END |
972
|
|
|
|
|
|
|
|
973
|
|
|
|
|
|
|
$HELP{'transform'}=$HELP{'xslt'}; |
974
|
|
|
|
|
|
|
$HELP{'xsl'}=$HELP{'xslt'}; |
975
|
|
|
|
|
|
|
$HELP{'xsltproc'}=$HELP{'xslt'}; |
976
|
|
|
|
|
|
|
$HELP{'process'}=$HELP{'xslt'}; |
977
|
|
|
|
|
|
|
|
978
|
|
|
|
|
|
|
$HELP{'documents'}=[<<'END']; |
979
|
|
|
|
|
|
|
usage: documents |
980
|
|
|
|
|
|
|
|
981
|
|
|
|
|
|
|
aliases: files docs |
982
|
|
|
|
|
|
|
|
983
|
|
|
|
|
|
|
description: |
984
|
|
|
|
|
|
|
Try to identify open documents and list their URIs and |
985
|
|
|
|
|
|
|
variables that contain them. |
986
|
|
|
|
|
|
|
|
987
|
|
|
|
|
|
|
see also: open close |
988
|
|
|
|
|
|
|
|
989
|
|
|
|
|
|
|
END |
990
|
|
|
|
|
|
|
|
991
|
|
|
|
|
|
|
$HELP{'files'}=$HELP{'documents'}; |
992
|
|
|
|
|
|
|
$HELP{'docs'}=$HELP{'documents'}; |
993
|
|
|
|
|
|
|
|
994
|
|
|
|
|
|
|
$HELP{'set_filename'}=[<<'END']; |
995
|
|
|
|
|
|
|
usage: set_filename [expression] [[document]] |
996
|
|
|
|
|
|
|
|
997
|
|
|
|
|
|
|
description: |
998
|
|
|
|
|
|
|
Changes filename or URL associated with a given document (or |
999
|
|
|
|
|
|
|
the current document, if only one argument is specified). |
1000
|
|
|
|
|
|
|
Document filename is initialized by the [open] command and |
1001
|
|
|
|
|
|
|
used e.g. by [save]. It can be queried in XPath expressions |
1002
|
|
|
|
|
|
|
using the [xsh:filename] function. |
1003
|
|
|
|
|
|
|
|
1004
|
|
|
|
|
|
|
see also: open save xsh:filename |
1005
|
|
|
|
|
|
|
|
1006
|
|
|
|
|
|
|
END |
1007
|
|
|
|
|
|
|
|
1008
|
|
|
|
|
|
|
|
1009
|
|
|
|
|
|
|
$HELP{'variables'}=[<<'END']; |
1010
|
|
|
|
|
|
|
usage: variables |
1011
|
|
|
|
|
|
|
|
1012
|
|
|
|
|
|
|
aliases: vars var |
1013
|
|
|
|
|
|
|
|
1014
|
|
|
|
|
|
|
description: |
1015
|
|
|
|
|
|
|
List all global variables and their current values. |
1016
|
|
|
|
|
|
|
|
1017
|
|
|
|
|
|
|
see also: documents defs |
1018
|
|
|
|
|
|
|
|
1019
|
|
|
|
|
|
|
END |
1020
|
|
|
|
|
|
|
|
1021
|
|
|
|
|
|
|
$HELP{'vars'}=$HELP{'variables'}; |
1022
|
|
|
|
|
|
|
$HELP{'var'}=$HELP{'variables'}; |
1023
|
|
|
|
|
|
|
|
1024
|
|
|
|
|
|
|
$HELP{'copy'}=[<<'END']; |
1025
|
|
|
|
|
|
|
usage: copy [--respective|:r] [expression] [location] [expression] |
1026
|
|
|
|
|
|
|
$results := copy [--respective|:r] [expression] [location] [expression] |
1027
|
|
|
|
|
|
|
|
1028
|
|
|
|
|
|
|
aliases: cp |
1029
|
|
|
|
|
|
|
|
1030
|
|
|
|
|
|
|
description: |
1031
|
|
|
|
|
|
|
Copies nodes in the first node-list [expression] (source |
1032
|
|
|
|
|
|
|
nodes) to the destinations determined by the the [location] |
1033
|
|
|
|
|
|
|
directive applied to nodes in the second node-list |
1034
|
|
|
|
|
|
|
[expression] (target nodes). If the source node-list contains |
1035
|
|
|
|
|
|
|
more than one node, than N'th node in the source node-list is |
1036
|
|
|
|
|
|
|
copied to the location relative to the N'th node in the target |
1037
|
|
|
|
|
|
|
node-list. |
1038
|
|
|
|
|
|
|
|
1039
|
|
|
|
|
|
|
If '--respective|:r' option is used, then the target node-list |
1040
|
|
|
|
|
|
|
[expression] is evaluated in the context of the source node |
1041
|
|
|
|
|
|
|
being copied. |
1042
|
|
|
|
|
|
|
|
1043
|
|
|
|
|
|
|
Possible values for [location] are: 'after', 'before', 'into', |
1044
|
|
|
|
|
|
|
'replace', 'append' and 'prepend'. The first three location |
1045
|
|
|
|
|
|
|
directives cause making a copy of the source nodes after, |
1046
|
|
|
|
|
|
|
before, and within (as the last child-node) the target nodes, |
1047
|
|
|
|
|
|
|
respectively. If 'replace' location directive is used, source |
1048
|
|
|
|
|
|
|
node are copied before the respective target nodes and target |
1049
|
|
|
|
|
|
|
nodes are removed. The 'append' and 'prepend' location |
1050
|
|
|
|
|
|
|
directives allow, depending on the destination node type, |
1051
|
|
|
|
|
|
|
either inserting copies of the source nodes as the first or |
1052
|
|
|
|
|
|
|
last child nodes of a destination element or |
1053
|
|
|
|
|
|
|
appending/prepending destination node data in case of |
1054
|
|
|
|
|
|
|
non-element destination nodes. See [location] argument type |
1055
|
|
|
|
|
|
|
for more detail. |
1056
|
|
|
|
|
|
|
|
1057
|
|
|
|
|
|
|
The command returns a node-list consisting of the copies of |
1058
|
|
|
|
|
|
|
all source nodes created by the command. |
1059
|
|
|
|
|
|
|
|
1060
|
|
|
|
|
|
|
Despite the fact the command is named "copy", nodes resulting |
1061
|
|
|
|
|
|
|
from copying the source nodes may pass through certain type |
1062
|
|
|
|
|
|
|
conversion before they are inserted at the appointed |
1063
|
|
|
|
|
|
|
destinations. This, however, only happens in cases where the |
1064
|
|
|
|
|
|
|
types of the source and target nodes are not compatible with |
1065
|
|
|
|
|
|
|
the location directive. See [location] argument type for more |
1066
|
|
|
|
|
|
|
detail. |
1067
|
|
|
|
|
|
|
|
1068
|
|
|
|
|
|
|
Note that XSH2 refuses to create multiple top-level elements |
1069
|
|
|
|
|
|
|
using 'copy', [move] and similar commands. |
1070
|
|
|
|
|
|
|
|
1071
|
|
|
|
|
|
|
Example: Replace living-thing elements in the document b with copies of |
1072
|
|
|
|
|
|
|
the corresponding creature elements from the document $a. |
1073
|
|
|
|
|
|
|
|
1074
|
|
|
|
|
|
|
xsh> copy $a//creature replace $b//living-thing |
1075
|
|
|
|
|
|
|
|
1076
|
|
|
|
|
|
|
Example: Copy every element into itself |
1077
|
|
|
|
|
|
|
|
1078
|
|
|
|
|
|
|
xsh> copy --respective $a//* into . |
1079
|
|
|
|
|
|
|
xsh> copy $a//* into $a//* #same as |
1080
|
|
|
|
|
|
|
above |
1081
|
|
|
|
|
|
|
|
1082
|
|
|
|
|
|
|
see also: xcopy move xmove insert xinsert |
1083
|
|
|
|
|
|
|
|
1084
|
|
|
|
|
|
|
END |
1085
|
|
|
|
|
|
|
|
1086
|
|
|
|
|
|
|
$HELP{'cp'}=$HELP{'copy'}; |
1087
|
|
|
|
|
|
|
|
1088
|
|
|
|
|
|
|
$HELP{'xcopy'}=[<<'END']; |
1089
|
|
|
|
|
|
|
usage: xcopy [--respective|:r] [--preserve-order|:p] [expression] [location] [expression] |
1090
|
|
|
|
|
|
|
|
1091
|
|
|
|
|
|
|
aliases: xcp |
1092
|
|
|
|
|
|
|
|
1093
|
|
|
|
|
|
|
description: |
1094
|
|
|
|
|
|
|
xcopy is similar to [copy], but copies all nodes in the first |
1095
|
|
|
|
|
|
|
node-list [expression] to all destinations determined by the |
1096
|
|
|
|
|
|
|
[location] directive relative to the second node-list |
1097
|
|
|
|
|
|
|
[expression]. See [copy] for detailed description of 'xcopy' |
1098
|
|
|
|
|
|
|
arguments. |
1099
|
|
|
|
|
|
|
|
1100
|
|
|
|
|
|
|
If '--respective|:r' option is used, then the target node-list |
1101
|
|
|
|
|
|
|
[expression] is evaluated in the context of the source node |
1102
|
|
|
|
|
|
|
being copied. |
1103
|
|
|
|
|
|
|
|
1104
|
|
|
|
|
|
|
The '--preserve-order|:p' option can be used to ensure that |
1105
|
|
|
|
|
|
|
the copied nodes are in the same relative order as the |
1106
|
|
|
|
|
|
|
corresponding source nodes. Otherwise, if [location] is |
1107
|
|
|
|
|
|
|
'after' or 'prepend', the relative order of the copied nodes |
1108
|
|
|
|
|
|
|
will be reversed, because source nodes are placed to the |
1109
|
|
|
|
|
|
|
target location one by one. |
1110
|
|
|
|
|
|
|
|
1111
|
|
|
|
|
|
|
Example: Copy all middle-earth creatures within the document $a into |
1112
|
|
|
|
|
|
|
every world of the document $b. |
1113
|
|
|
|
|
|
|
|
1114
|
|
|
|
|
|
|
xsh> xcopy $a/middle-earth/creature into $b//world |
1115
|
|
|
|
|
|
|
|
1116
|
|
|
|
|
|
|
see also: copy move xmove insert xinsert |
1117
|
|
|
|
|
|
|
|
1118
|
|
|
|
|
|
|
END |
1119
|
|
|
|
|
|
|
|
1120
|
|
|
|
|
|
|
$HELP{'xcp'}=$HELP{'xcopy'}; |
1121
|
|
|
|
|
|
|
|
1122
|
|
|
|
|
|
|
$HELP{'lcd'}=[<<'END']; |
1123
|
|
|
|
|
|
|
usage: lcd [expression] |
1124
|
|
|
|
|
|
|
|
1125
|
|
|
|
|
|
|
aliases: chdir |
1126
|
|
|
|
|
|
|
|
1127
|
|
|
|
|
|
|
description: |
1128
|
|
|
|
|
|
|
Changes the filesystem working directory to [expression], if |
1129
|
|
|
|
|
|
|
possible. If [expression] is omitted, changes to the directory |
1130
|
|
|
|
|
|
|
specified in HOME environment variable, if set; if not, |
1131
|
|
|
|
|
|
|
changes to the directory specified by LOGDIR environment |
1132
|
|
|
|
|
|
|
variable. |
1133
|
|
|
|
|
|
|
|
1134
|
|
|
|
|
|
|
END |
1135
|
|
|
|
|
|
|
|
1136
|
|
|
|
|
|
|
$HELP{'chdir'}=$HELP{'lcd'}; |
1137
|
|
|
|
|
|
|
|
1138
|
|
|
|
|
|
|
$HELP{'insert'}=[<<'END']; |
1139
|
|
|
|
|
|
|
usage: insert [--namespace|:n [expression]] [node-type] [expression] [location] [xpath] |
1140
|
|
|
|
|
|
|
|
1141
|
|
|
|
|
|
|
aliases: add |
1142
|
|
|
|
|
|
|
|
1143
|
|
|
|
|
|
|
description: |
1144
|
|
|
|
|
|
|
Works just like [xinsert], except that the new node is |
1145
|
|
|
|
|
|
|
attached only the first node matched. |
1146
|
|
|
|
|
|
|
|
1147
|
|
|
|
|
|
|
see also: xinsert move xmove |
1148
|
|
|
|
|
|
|
|
1149
|
|
|
|
|
|
|
END |
1150
|
|
|
|
|
|
|
|
1151
|
|
|
|
|
|
|
$HELP{'add'}=$HELP{'insert'}; |
1152
|
|
|
|
|
|
|
|
1153
|
|
|
|
|
|
|
$HELP{'wrap'}=[<<'END']; |
1154
|
|
|
|
|
|
|
usage: wrap [--namespace [expression]] |
1155
|
|
|
|
|
|
|
[ [--inner] | [--while|:W [expression]] [--until|:U [expression]] |
1156
|
|
|
|
|
|
|
[--skip-whitespace|:w] [--skip-comments|:c] [--skip-pi|:p] ] |
1157
|
|
|
|
|
|
|
[expression] [xpath] |
1158
|
|
|
|
|
|
|
|
1159
|
|
|
|
|
|
|
description: |
1160
|
|
|
|
|
|
|
For each node matching the [xpath] argument, this command |
1161
|
|
|
|
|
|
|
creates a new element node according to a given [expression] |
1162
|
|
|
|
|
|
|
(in the same way as [xinsert] does) which replaces the |
1163
|
|
|
|
|
|
|
matching node, and moves the matching node into this newly |
1164
|
|
|
|
|
|
|
created element. If namespace [expression] is given, the |
1165
|
|
|
|
|
|
|
namespace is applied on the created element. The command |
1166
|
|
|
|
|
|
|
returns a node-list consisting of the elements created. |
1167
|
|
|
|
|
|
|
|
1168
|
|
|
|
|
|
|
With '--inner' (or ':i') flag the command wraps children nodes |
1169
|
|
|
|
|
|
|
of the matching node rather than the node it self the |
1170
|
|
|
|
|
|
|
following sense: for each matching node a new element node is |
1171
|
|
|
|
|
|
|
created, but this time it is placed into the matching node and |
1172
|
|
|
|
|
|
|
all previous children of the matching node are moved into the |
1173
|
|
|
|
|
|
|
newly created node. In this mode, all non-element matching |
1174
|
|
|
|
|
|
|
nodes are ignored. This flag cannot be used together with |
1175
|
|
|
|
|
|
|
'--while' and '--until', which we describe next. |
1176
|
|
|
|
|
|
|
|
1177
|
|
|
|
|
|
|
'--while' (':W') and/or '--until' (':U') arguments can be |
1178
|
|
|
|
|
|
|
provided in order to move a sequence of adjacent siblings |
1179
|
|
|
|
|
|
|
following the matching node into the newly created element. In |
1180
|
|
|
|
|
|
|
this way the newly created element wraps not just the matching |
1181
|
|
|
|
|
|
|
node itself but a range of nodes starting at the matching node |
1182
|
|
|
|
|
|
|
and ending either before a first following node matching the |
1183
|
|
|
|
|
|
|
expression of '--until', or before a first following node not |
1184
|
|
|
|
|
|
|
matching the expression of '--while', or at the last sibling |
1185
|
|
|
|
|
|
|
if neither of the prior apply. Both these expressions are |
1186
|
|
|
|
|
|
|
evaluated in the context of the currently tested sibling and |
1187
|
|
|
|
|
|
|
prior to the creation of the wrapping element. The context |
1188
|
|
|
|
|
|
|
position for these expressions is 1 at the first sibling |
1189
|
|
|
|
|
|
|
following the matching node and increases with each tested |
1190
|
|
|
|
|
|
|
sibling; the context size is the number of all siblings |
1191
|
|
|
|
|
|
|
following the matching node. It is important to mention that |
1192
|
|
|
|
|
|
|
siblings wrapped in this way are excluded from further |
1193
|
|
|
|
|
|
|
processing by [wrap] even if included in the node-list |
1194
|
|
|
|
|
|
|
produced by the [xpath] argument. This allows to easily wrap |
1195
|
|
|
|
|
|
|
certain adjacent elements without worrying about some elements |
1196
|
|
|
|
|
|
|
being wrapped multiple times (for example, 'wrap :W x y //x' |
1197
|
|
|
|
|
|
|
wraps each sequence of adjacent elements '' in a ''). |
1198
|
|
|
|
|
|
|
|
1199
|
|
|
|
|
|
|
'--skip-whitespace' (':w'), '--skip-comments' (':c'), and |
1200
|
|
|
|
|
|
|
'--skip-pi' (':p') can be used in combination with '--while' |
1201
|
|
|
|
|
|
|
(':W') and/or '--until' (':U') to skip testing the expressions |
1202
|
|
|
|
|
|
|
on white-space text nodes, comments, and/or processing |
1203
|
|
|
|
|
|
|
instruction, respectively. Such nodes are only included in the |
1204
|
|
|
|
|
|
|
wrapped range if followed by a sibling that is to be wrapped. |
1205
|
|
|
|
|
|
|
|
1206
|
|
|
|
|
|
|
Example: |
1207
|
|
|
|
|
|
|
$scratch/> ls /; |
1208
|
|
|
|
|
|
|
|
1209
|
|
|
|
|
|
|
|
1210
|
|
|
|
|
|
|
|
1211
|
|
|
|
|
|
|
$scratch/> wrap 'foo' *; |
1212
|
|
|
|
|
|
|
$scratch/> insert attribute 'bar=baz' into /foo; |
1213
|
|
|
|
|
|
|
$scratch/> insert text 'some text' into //scratch; |
1214
|
|
|
|
|
|
|
$scratch/> wrap --namespace 'http://foo/bar' 'a:A' //@*; |
1215
|
|
|
|
|
|
|
$scratch/> $wrapper := wrap 'text aaa="bbb"' //text(); |
1216
|
|
|
|
|
|
|
$scratch/> wrap '' //*; |
1217
|
|
|
|
|
|
|
$scratch/> ls /; |
1218
|
|
|
|
|
|
|
|
1219
|
|
|
|
|
|
|
|
1220
|
|
|
|
|
|
|
|
1221
|
|
|
|
|
|
|
|
1222
|
|
|
|
|
|
|
|
1223
|
|
|
|
|
|
|
|
1224
|
|
|
|
|
|
|
some text |
1225
|
|
|
|
|
|
|
|
1226
|
|
|
|
|
|
|
|
1227
|
|
|
|
|
|
|
|
1228
|
|
|
|
|
|
|
|
1229
|
|
|
|
|
|
|
|
1230
|
|
|
|
|
|
|
|
1231
|
|
|
|
|
|
|
|
1232
|
|
|
|
|
|
|
|
1233
|
|
|
|
|
|
|
|
1234
|
|
|
|
|
|
|
$scratch/> ls $wrapper; |
1235
|
|
|
|
|
|
|
some text |
1236
|
|
|
|
|
|
|
|
1237
|
|
|
|
|
|
|
|
1238
|
|
|
|
|
|
|
$scratch/> wrap --inner bar //foo |
1239
|
|
|
|
|
|
|
$scratch/> ls /; |
1240
|
|
|
|
|
|
|
|
1241
|
|
|
|
|
|
|
|
1242
|
|
|
|
|
|
|
|
1243
|
|
|
|
|
|
|
|
1244
|
|
|
|
|
|
|
|
1245
|
|
|
|
|
|
|
|
1246
|
|
|
|
|
|
|
|
1247
|
|
|
|
|
|
|
some text |
1248
|
|
|
|
|
|
|
|
1249
|
|
|
|
|
|
|
|
1250
|
|
|
|
|
|
|
|
1251
|
|
|
|
|
|
|
|
1252
|
|
|
|
|
|
|
|
1253
|
|
|
|
|
|
|
|
1254
|
|
|
|
|
|
|
|
1255
|
|
|
|
|
|
|
|
1256
|
|
|
|
|
|
|
|
1257
|
|
|
|
|
|
|
|
1258
|
|
|
|
|
|
|
Example: Wrapping a range of adjacent nodes |
1259
|
|
|
|
|
|
|
|
1260
|
|
|
|
|
|
|
# prepare the test document |
1261
|
|
|
|
|
|
|
$scratch/> rm /scratch/node(); # cleanup the document |
1262
|
|
|
|
|
|
|
$scratch/> set /scratch/li[5]; # create 5 elements |
1263
|
|
|
|
|
|
|
$scratch/> set /scratch/li[3]/following-sibling::li; # add after the 3rd |
1264
|
|
|
|
|
|
|
$scratch/> for //li set . position(); # number the elements |
1265
|
|
|
|
|
|
|
$scratch/> ls / |
1266
|
|
|
|
|
|
|
|
1267
|
|
|
|
|
|
|
|
1268
|
|
|
|
|
|
|
1 |
1269
|
|
|
|
|
|
|
2 |
1270
|
|
|
|
|
|
|
3 |
1271
|
|
|
|
|
|
|
|
1272
|
|
|
|
|
|
|
4 |
1273
|
|
|
|
|
|
|
5 |
1274
|
|
|
|
|
|
|
|
1275
|
|
|
|
|
|
|
# wrap adjacent elements into an |
1276
|
|
|
|
|
|
|
$scratch/> wrap --skip-whitespace --while self::li ol //li; |
1277
|
|
|
|
|
|
|
$scratch/> ls / |
1278
|
|
|
|
|
|
|
|
1279
|
|
|
|
|
|
|
|
1280
|
|
|
|
|
|
|
|
1281
|
|
|
|
|
|
|
1 |
1282
|
|
|
|
|
|
|
2 |
1283
|
|
|
|
|
|
|
3 |
1284
|
|
|
|
|
|
|
|
1285
|
|
|
|
|
|
|
|
1286
|
|
|
|
|
|
|
|
1287
|
|
|
|
|
|
|
4 |
1288
|
|
|
|
|
|
|
5 |
1289
|
|
|
|
|
|
|
|
1290
|
|
|
|
|
|
|
|
1291
|
|
|
|
|
|
|
|
1292
|
|
|
|
|
|
|
see also: xinsert insert move xmove |
1293
|
|
|
|
|
|
|
|
1294
|
|
|
|
|
|
|
END |
1295
|
|
|
|
|
|
|
|
1296
|
|
|
|
|
|
|
|
1297
|
|
|
|
|
|
|
$HELP{'wrap-span'}=[<<'END']; |
1298
|
|
|
|
|
|
|
usage: wrap-span [--namespace [expression]] [expression] [expression] [expression] |
1299
|
|
|
|
|
|
|
|
1300
|
|
|
|
|
|
|
aliases: wrap_span |
1301
|
|
|
|
|
|
|
|
1302
|
|
|
|
|
|
|
description: |
1303
|
|
|
|
|
|
|
This command is very similar to [wrap] command, except that it |
1304
|
|
|
|
|
|
|
works on spans of nodes. It wraps spans (i.e. sequence of |
1305
|
|
|
|
|
|
|
adjacent nodes between (and including) a start node and an end |
1306
|
|
|
|
|
|
|
node) with a new element whose name is specified as the first |
1307
|
|
|
|
|
|
|
argument. Nodes within each span must have the same parent |
1308
|
|
|
|
|
|
|
node. The spans to be wrapped are defined by a pair of |
1309
|
|
|
|
|
|
|
node-lists in the second and third argument. The first |
1310
|
|
|
|
|
|
|
node-list specifies the start node of one or more spans, while |
1311
|
|
|
|
|
|
|
the second node-list should contain the corresponding end |
1312
|
|
|
|
|
|
|
nodes. The two node-lists must evaluate to the exactly same |
1313
|
|
|
|
|
|
|
number of nodes, otherwise a runtime error is reported. The |
1314
|
|
|
|
|
|
|
N'th span is then defined as a span starting on the N'th node |
1315
|
|
|
|
|
|
|
in the start node-list and ending at the N'th node in the end |
1316
|
|
|
|
|
|
|
node-list. |
1317
|
|
|
|
|
|
|
|
1318
|
|
|
|
|
|
|
All nodes within the spans are removed from the document and |
1319
|
|
|
|
|
|
|
placed into the newly generated elements. The wrapping |
1320
|
|
|
|
|
|
|
elements are put back into the document tree at the positions |
1321
|
|
|
|
|
|
|
previously occupied by the node-spans. |
1322
|
|
|
|
|
|
|
|
1323
|
|
|
|
|
|
|
The command returns a node-list containing the newly created |
1324
|
|
|
|
|
|
|
wrapping elements. |
1325
|
|
|
|
|
|
|
|
1326
|
|
|
|
|
|
|
Example: |
1327
|
|
|
|
|
|
|
xsh $scratch/> $foo := create { "\n\n\n\n" }; |
1328
|
|
|
|
|
|
|
xsh $foo/> wrap-span 'span' //a //b; |
1329
|
|
|
|
|
|
|
xsh $foo/> ls /; |
1330
|
|
|
|
|
|
|
|
1331
|
|
|
|
|
|
|
|
1332
|
|
|
|
|
|
|
|
1333
|
|
|
|
|
|
|
|
1334
|
|
|
|
|
|
|
|
1335
|
|
|
|
|
|
|
|
1336
|
|
|
|
|
|
|
|
1337
|
|
|
|
|
|
|
see also: xinsert insert move xmove |
1338
|
|
|
|
|
|
|
|
1339
|
|
|
|
|
|
|
END |
1340
|
|
|
|
|
|
|
|
1341
|
|
|
|
|
|
|
$HELP{'wrap_span'}=$HELP{'wrap-span'}; |
1342
|
|
|
|
|
|
|
|
1343
|
|
|
|
|
|
|
$HELP{'xinsert'}=[<<'END']; |
1344
|
|
|
|
|
|
|
usage: xinsert [--namespace [expression]] [node-type] [expression] [location] [xpath] |
1345
|
|
|
|
|
|
|
|
1346
|
|
|
|
|
|
|
aliases: xadd |
1347
|
|
|
|
|
|
|
|
1348
|
|
|
|
|
|
|
description: |
1349
|
|
|
|
|
|
|
Create new nodes of the [node-type] given in the 1st argument |
1350
|
|
|
|
|
|
|
of name specified in the 2nd argument and insert them to |
1351
|
|
|
|
|
|
|
[location]s relative to nodes in the node-list specified in |
1352
|
|
|
|
|
|
|
the 4th argument. |
1353
|
|
|
|
|
|
|
|
1354
|
|
|
|
|
|
|
For element nodes, the the 2nd argument [expression] should |
1355
|
|
|
|
|
|
|
evaluate to something like "
|
1356
|
|
|
|
|
|
|
...>". The '<' and '>' characters are optional. If no |
1357
|
|
|
|
|
|
|
attributes are used, the expression may simply consist the |
1358
|
|
|
|
|
|
|
element name. Note, that in the first case, the quotes are |
1359
|
|
|
|
|
|
|
required since the expression contains spaces. |
1360
|
|
|
|
|
|
|
|
1361
|
|
|
|
|
|
|
Attribute nodes use the following syntax: "att-name='attvalue' |
1362
|
|
|
|
|
|
|
[...]". |
1363
|
|
|
|
|
|
|
|
1364
|
|
|
|
|
|
|
For the other types of nodes (text, cdata, comments) the |
1365
|
|
|
|
|
|
|
expression should contain the node's literal content. Again, |
1366
|
|
|
|
|
|
|
it is necessary to quote all whitespace and special characters |
1367
|
|
|
|
|
|
|
as in any expression argument. |
1368
|
|
|
|
|
|
|
|
1369
|
|
|
|
|
|
|
The [location] argument should be one of: 'after', 'before', |
1370
|
|
|
|
|
|
|
'into', 'replace', 'append' or 'prepend'. See documentation of |
1371
|
|
|
|
|
|
|
the [location] argument type for more detail. |
1372
|
|
|
|
|
|
|
|
1373
|
|
|
|
|
|
|
Optionally, for element and attribute nodes, a namespace may |
1374
|
|
|
|
|
|
|
be specified with '--namespace' or ':n'. If used, the |
1375
|
|
|
|
|
|
|
expression should evaluate to the desired namespace URI and |
1376
|
|
|
|
|
|
|
the name of the element or attribute being inserted must have |
1377
|
|
|
|
|
|
|
a prefix. |
1378
|
|
|
|
|
|
|
|
1379
|
|
|
|
|
|
|
The command returns a node-list consisting of nodes it |
1380
|
|
|
|
|
|
|
created. |
1381
|
|
|
|
|
|
|
|
1382
|
|
|
|
|
|
|
Note, that instead of 'xinsert', you can alternatively use one |
1383
|
|
|
|
|
|
|
of [xsh:new-attribute], [xsh:new-cdata], [xsh:new-chunk], |
1384
|
|
|
|
|
|
|
[xsh:new-comment], [xsh:new-element], [xsh:new-element-ns], |
1385
|
|
|
|
|
|
|
[xsh:new-pi], and [xsh:new-text] together with the command |
1386
|
|
|
|
|
|
|
[xcopy]. |
1387
|
|
|
|
|
|
|
|
1388
|
|
|
|
|
|
|
Example: Give each chapter a provisional title element. |
1389
|
|
|
|
|
|
|
|
1390
|
|
|
|
|
|
|
xsh> my $new_titles := xinsert element "" \ |
1391
|
|
|
|
|
|
|
into /book/chapter |
1392
|
|
|
|
|
|
|
xsh> xinsert text "Change me!" into $new_titles; |
1393
|
|
|
|
|
|
|
|
1394
|
|
|
|
|
|
|
Example: Same as above, using xcopy and xsh:new-... instead of xinsert |
1395
|
|
|
|
|
|
|
|
1396
|
|
|
|
|
|
|
xsh> my $new_titles := xcopy xsh:new-element("title","font-size","large","underline","yes") \ |
1397
|
|
|
|
|
|
|
into /book/chapter |
1398
|
|
|
|
|
|
|
xsh> xcopy xsh:new-text("Change me!") into $new_titles; |
1399
|
|
|
|
|
|
|
|
1400
|
|
|
|
|
|
|
see also: insert move xmove |
1401
|
|
|
|
|
|
|
|
1402
|
|
|
|
|
|
|
END |
1403
|
|
|
|
|
|
|
|
1404
|
|
|
|
|
|
|
$HELP{'xadd'}=$HELP{'xinsert'}; |
1405
|
|
|
|
|
|
|
|
1406
|
|
|
|
|
|
|
$HELP{'node-type'}=[<<'END']; |
1407
|
|
|
|
|
|
|
Node-type argument type |
1408
|
|
|
|
|
|
|
|
1409
|
|
|
|
|
|
|
description: |
1410
|
|
|
|
|
|
|
One of: element, attribute, text, cdata, comment, chunk and |
1411
|
|
|
|
|
|
|
(EXPERIMENTALLY!) entity_reference. A chunk is a character |
1412
|
|
|
|
|
|
|
string which forms a well-balanced piece of XML. |
1413
|
|
|
|
|
|
|
|
1414
|
|
|
|
|
|
|
Example: |
1415
|
|
|
|
|
|
|
add element hobbit into //middle-earth/creatures; |
1416
|
|
|
|
|
|
|
add attribute 'name="Bilbo"' into //middle-earth/creatures/hobbit[last()]; |
1417
|
|
|
|
|
|
|
add chunk 'A small guy from Shire.' |
1418
|
|
|
|
|
|
|
into //middle-earth/creatures; |
1419
|
|
|
|
|
|
|
|
1420
|
|
|
|
|
|
|
END |
1421
|
|
|
|
|
|
|
|
1422
|
|
|
|
|
|
|
|
1423
|
|
|
|
|
|
|
$HELP{'location'}=[<<'END']; |
1424
|
|
|
|
|
|
|
Location argument type |
1425
|
|
|
|
|
|
|
|
1426
|
|
|
|
|
|
|
description: |
1427
|
|
|
|
|
|
|
One of: 'after', 'before', 'into', 'append', 'prepend', |
1428
|
|
|
|
|
|
|
'replace'. |
1429
|
|
|
|
|
|
|
|
1430
|
|
|
|
|
|
|
This argument is required by all commands that insert nodes to |
1431
|
|
|
|
|
|
|
a document in some way to a destination described by an XPath |
1432
|
|
|
|
|
|
|
expression. The meaning of the values listed above is supposed |
1433
|
|
|
|
|
|
|
be obvious in most cases, however the exact semantics for |
1434
|
|
|
|
|
|
|
location argument values depends on types of both the source |
1435
|
|
|
|
|
|
|
node and the target node. |
1436
|
|
|
|
|
|
|
|
1437
|
|
|
|
|
|
|
'after/before' place the node right after/before the |
1438
|
|
|
|
|
|
|
destination node, except for when the destination node is a |
1439
|
|
|
|
|
|
|
document node or one of the source nodes is an attribute: If |
1440
|
|
|
|
|
|
|
the destination node is a document node, the source node is |
1441
|
|
|
|
|
|
|
attached to the end/beginning of the document (remember: there |
1442
|
|
|
|
|
|
|
is no "after/before a document"). If both the source and |
1443
|
|
|
|
|
|
|
destination nodes are attributes, then the source node is |
1444
|
|
|
|
|
|
|
simply attached to the element containing the destination node |
1445
|
|
|
|
|
|
|
(remember: there is no order on attribute nodes). If the |
1446
|
|
|
|
|
|
|
destination node is an attribute but the source node is of a |
1447
|
|
|
|
|
|
|
different type, then the textual content of the source node is |
1448
|
|
|
|
|
|
|
appended to the value of the destination attribute (i.e. in |
1449
|
|
|
|
|
|
|
this case after/before act just as append/prepend). |
1450
|
|
|
|
|
|
|
|
1451
|
|
|
|
|
|
|
'append/prepend' appends/prepends the source node to the |
1452
|
|
|
|
|
|
|
destination node. If the destination node can contain other |
1453
|
|
|
|
|
|
|
nodes (i.e. it is an element or a document node) then the |
1454
|
|
|
|
|
|
|
entire source node is attached to it. In case of other |
1455
|
|
|
|
|
|
|
destination node types, the textual content of the source node |
1456
|
|
|
|
|
|
|
is appended/prepended to the content of the destination node. |
1457
|
|
|
|
|
|
|
|
1458
|
|
|
|
|
|
|
'into' can also be used to place the source node to the end of |
1459
|
|
|
|
|
|
|
an element (in the same way as 'append'), to attach an |
1460
|
|
|
|
|
|
|
attribute to an element, or, if the destination node is a text |
1461
|
|
|
|
|
|
|
node, cdata section, processing-instruction, attribute or |
1462
|
|
|
|
|
|
|
comment, to replace its textual content with the textual |
1463
|
|
|
|
|
|
|
content of the source node. |
1464
|
|
|
|
|
|
|
|
1465
|
|
|
|
|
|
|
'replace' replaces the entire destination node with the source |
1466
|
|
|
|
|
|
|
node except for the case when the destination node is an |
1467
|
|
|
|
|
|
|
attribute and the source node is not. In such a case only the |
1468
|
|
|
|
|
|
|
value of the destination attribute is replaced with the |
1469
|
|
|
|
|
|
|
textual content of the source node. Note also that document |
1470
|
|
|
|
|
|
|
node can never be replaced. |
1471
|
|
|
|
|
|
|
|
1472
|
|
|
|
|
|
|
END |
1473
|
|
|
|
|
|
|
|
1474
|
|
|
|
|
|
|
|
1475
|
|
|
|
|
|
|
$HELP{'move'}=[<<'END']; |
1476
|
|
|
|
|
|
|
usage: move [xpath] [location] [xpath] |
1477
|
|
|
|
|
|
|
|
1478
|
|
|
|
|
|
|
aliases: mv |
1479
|
|
|
|
|
|
|
|
1480
|
|
|
|
|
|
|
description: |
1481
|
|
|
|
|
|
|
'move' command acts exactly like [copy], except that it |
1482
|
|
|
|
|
|
|
removes the source nodes after a successful copy. Remember |
1483
|
|
|
|
|
|
|
that the moved nodes are actually different nodes from the |
1484
|
|
|
|
|
|
|
original ones (which may not be obvious when moving nodes |
1485
|
|
|
|
|
|
|
within a single document into locations that do not require |
1486
|
|
|
|
|
|
|
type conversion). So, after the move, the original nodes don't |
1487
|
|
|
|
|
|
|
belong to any document and are automatically destroyed unless |
1488
|
|
|
|
|
|
|
some variable still contains to them. |
1489
|
|
|
|
|
|
|
|
1490
|
|
|
|
|
|
|
This command returns a node-list consisting of nodes it |
1491
|
|
|
|
|
|
|
created on the target locations. |
1492
|
|
|
|
|
|
|
|
1493
|
|
|
|
|
|
|
See [copy] for more details on how the copies of the moved |
1494
|
|
|
|
|
|
|
nodes are created. |
1495
|
|
|
|
|
|
|
|
1496
|
|
|
|
|
|
|
see also: xmove copy xcopy insert xinsert |
1497
|
|
|
|
|
|
|
|
1498
|
|
|
|
|
|
|
END |
1499
|
|
|
|
|
|
|
|
1500
|
|
|
|
|
|
|
$HELP{'mv'}=$HELP{'move'}; |
1501
|
|
|
|
|
|
|
|
1502
|
|
|
|
|
|
|
$HELP{'xmove'}=[<<'END']; |
1503
|
|
|
|
|
|
|
usage: xmove [--respective|:r] [--preserve-order|:p] [xpath] [location] [xpath] |
1504
|
|
|
|
|
|
|
|
1505
|
|
|
|
|
|
|
aliases: xmv |
1506
|
|
|
|
|
|
|
|
1507
|
|
|
|
|
|
|
description: |
1508
|
|
|
|
|
|
|
Like [xcopy], except that 'xmove' removes the source nodes |
1509
|
|
|
|
|
|
|
after a successful copy. Remember that the moved nodes are |
1510
|
|
|
|
|
|
|
actually different nodes from the original ones (which may not |
1511
|
|
|
|
|
|
|
be obvious when moving nodes within a single document into |
1512
|
|
|
|
|
|
|
locations that do not require type conversion). So, after the |
1513
|
|
|
|
|
|
|
move, the original nodes don't belong to any document and are |
1514
|
|
|
|
|
|
|
automatically destroyed unless still contained in some |
1515
|
|
|
|
|
|
|
variable. |
1516
|
|
|
|
|
|
|
|
1517
|
|
|
|
|
|
|
This command returns a node-list consisting of all nodes it |
1518
|
|
|
|
|
|
|
created on the target locations. |
1519
|
|
|
|
|
|
|
|
1520
|
|
|
|
|
|
|
If '--respective|:r' option is used, then the target node-list |
1521
|
|
|
|
|
|
|
[expression] is evaluated in the context of the source node |
1522
|
|
|
|
|
|
|
being copied. |
1523
|
|
|
|
|
|
|
|
1524
|
|
|
|
|
|
|
The '--preserve-order|:p' option can be used to ensure that |
1525
|
|
|
|
|
|
|
the copied nodes are in the same relative order as the |
1526
|
|
|
|
|
|
|
corresponding source nodes. Otherwise, if [location] is |
1527
|
|
|
|
|
|
|
'after' or 'prepend', the relative order of the copied nodes |
1528
|
|
|
|
|
|
|
will be reversed, because source nodes are placed to the |
1529
|
|
|
|
|
|
|
target location one by one. |
1530
|
|
|
|
|
|
|
|
1531
|
|
|
|
|
|
|
See [xcopy] for more details on how the copies of the moved |
1532
|
|
|
|
|
|
|
nodes are created. |
1533
|
|
|
|
|
|
|
|
1534
|
|
|
|
|
|
|
The following example demonstrates how 'xmove' can be used to |
1535
|
|
|
|
|
|
|
get rid of HTML '' elements while preserving their |
1536
|
|
|
|
|
|
|
content. As an exercise, try to figure out why simple 'foreach |
1537
|
|
|
|
|
|
|
//font { xmove node() replace . }' would not work here. |
1538
|
|
|
|
|
|
|
|
1539
|
|
|
|
|
|
|
Example: Get rid of all tags |
1540
|
|
|
|
|
|
|
|
1541
|
|
|
|
|
|
|
while //font { |
1542
|
|
|
|
|
|
|
foreach //font { |
1543
|
|
|
|
|
|
|
xmove node() replace .; |
1544
|
|
|
|
|
|
|
} |
1545
|
|
|
|
|
|
|
} |
1546
|
|
|
|
|
|
|
|
1547
|
|
|
|
|
|
|
see also: move copy xcopy insert xinsert |
1548
|
|
|
|
|
|
|
|
1549
|
|
|
|
|
|
|
END |
1550
|
|
|
|
|
|
|
|
1551
|
|
|
|
|
|
|
$HELP{'xmv'}=$HELP{'xmove'}; |
1552
|
|
|
|
|
|
|
|
1553
|
|
|
|
|
|
|
$HELP{'clone'}=[<<'END']; |
1554
|
|
|
|
|
|
|
usage: $doc := clone [document] |
1555
|
|
|
|
|
|
|
|
1556
|
|
|
|
|
|
|
aliases: dup |
1557
|
|
|
|
|
|
|
|
1558
|
|
|
|
|
|
|
description: |
1559
|
|
|
|
|
|
|
Create and return a copy of a given [document]. Unless |
1560
|
|
|
|
|
|
|
[switch-to-new-documents] configuration flag is turned off, |
1561
|
|
|
|
|
|
|
the root node of the new document becomes the current node. |
1562
|
|
|
|
|
|
|
|
1563
|
|
|
|
|
|
|
Calling this command only makes sense if either |
1564
|
|
|
|
|
|
|
[switch-to-new-documents] is set, or if the result is assigned |
1565
|
|
|
|
|
|
|
to a variable or passed to another XSH2 command using the |
1566
|
|
|
|
|
|
|
'&{...}' syntax, since otherwise the newly created copy of the |
1567
|
|
|
|
|
|
|
document is automatically garbage-collected and destroyed. |
1568
|
|
|
|
|
|
|
|
1569
|
|
|
|
|
|
|
see also: open close enc documents |
1570
|
|
|
|
|
|
|
|
1571
|
|
|
|
|
|
|
END |
1572
|
|
|
|
|
|
|
|
1573
|
|
|
|
|
|
|
$HELP{'dup'}=$HELP{'clone'}; |
1574
|
|
|
|
|
|
|
|
1575
|
|
|
|
|
|
|
$HELP{'normalize'}=[<<'END']; |
1576
|
|
|
|
|
|
|
usage: normalize [expression] |
1577
|
|
|
|
|
|
|
|
1578
|
|
|
|
|
|
|
description: |
1579
|
|
|
|
|
|
|
'normalize' evaluates given [expression] to a node-list and |
1580
|
|
|
|
|
|
|
puts all text nodes in the full depth of the sub-tree |
1581
|
|
|
|
|
|
|
underneath each node in the node-list into a "normal" form |
1582
|
|
|
|
|
|
|
where only structure (e.g., elements, comments, processing |
1583
|
|
|
|
|
|
|
instructions, CDATA sections, and entity references) separates |
1584
|
|
|
|
|
|
|
text nodes, i.e., there are neither adjacent text nodes nor |
1585
|
|
|
|
|
|
|
empty text nodes. |
1586
|
|
|
|
|
|
|
|
1587
|
|
|
|
|
|
|
Note, that most XSH2 commands automatically join adjacent text |
1588
|
|
|
|
|
|
|
nodes. |
1589
|
|
|
|
|
|
|
|
1590
|
|
|
|
|
|
|
END |
1591
|
|
|
|
|
|
|
|
1592
|
|
|
|
|
|
|
|
1593
|
|
|
|
|
|
|
$HELP{'strip-whitespace'}=[<<'END']; |
1594
|
|
|
|
|
|
|
usage: strip-whitespace [expression] |
1595
|
|
|
|
|
|
|
|
1596
|
|
|
|
|
|
|
aliases: strip_whitespace |
1597
|
|
|
|
|
|
|
|
1598
|
|
|
|
|
|
|
description: |
1599
|
|
|
|
|
|
|
'strip-whitespace' removes all leading and trailing whitespace |
1600
|
|
|
|
|
|
|
from given nodes. If applied to an element node, it removes |
1601
|
|
|
|
|
|
|
all leading and trailing child whitespace-only text nodes and |
1602
|
|
|
|
|
|
|
CDATA sections. |
1603
|
|
|
|
|
|
|
|
1604
|
|
|
|
|
|
|
END |
1605
|
|
|
|
|
|
|
|
1606
|
|
|
|
|
|
|
$HELP{'strip_whitespace'}=$HELP{'strip-whitespace'}; |
1607
|
|
|
|
|
|
|
|
1608
|
|
|
|
|
|
|
$HELP{'ls'}=[<<'END']; |
1609
|
|
|
|
|
|
|
usage: ls [--fold|:f] [--fold-attrs|:A] [--indent|:i | --no-indent|:I] |
1610
|
|
|
|
|
|
|
[--depth|:d [expression]] [[expression]] |
1611
|
|
|
|
|
|
|
|
1612
|
|
|
|
|
|
|
aliases: list |
1613
|
|
|
|
|
|
|
|
1614
|
|
|
|
|
|
|
description: |
1615
|
|
|
|
|
|
|
Print XML representation of a given [expression], in |
1616
|
|
|
|
|
|
|
particular, if used with an [xpath], list parts of the |
1617
|
|
|
|
|
|
|
document matching given expression. |
1618
|
|
|
|
|
|
|
|
1619
|
|
|
|
|
|
|
If used without an argument, current node is listed to the |
1620
|
|
|
|
|
|
|
depth 1 (see below). |
1621
|
|
|
|
|
|
|
|
1622
|
|
|
|
|
|
|
'--depth' or ':d' argument may be used to specify depth of the |
1623
|
|
|
|
|
|
|
XML listing. If negative, the listing depth is unlimited. All |
1624
|
|
|
|
|
|
|
content below the specified depth is replaced with an ellipsis |
1625
|
|
|
|
|
|
|
('...'). |
1626
|
|
|
|
|
|
|
|
1627
|
|
|
|
|
|
|
'--fold' or ':f' option makes the listing fold elements marked |
1628
|
|
|
|
|
|
|
using the [fold] command are folded, i.e. listed only to the |
1629
|
|
|
|
|
|
|
depth specified in the folding mark. |
1630
|
|
|
|
|
|
|
|
1631
|
|
|
|
|
|
|
'--fold-attrs' or ':A' option avoids listing of attributes of |
1632
|
|
|
|
|
|
|
the folded elements (i.e. elements on the lowest level of |
1633
|
|
|
|
|
|
|
listing). Folded attributes are replaced with ellipsis |
1634
|
|
|
|
|
|
|
('...'). |
1635
|
|
|
|
|
|
|
|
1636
|
|
|
|
|
|
|
'--indent' (':i') and '--no-indent' (':I') may be used to |
1637
|
|
|
|
|
|
|
enforce/suppress indentation, overriding current setting (see |
1638
|
|
|
|
|
|
|
command [indent]). |
1639
|
|
|
|
|
|
|
|
1640
|
|
|
|
|
|
|
Unless in [quiet] mode, this command also prints the number of |
1641
|
|
|
|
|
|
|
(top-level) nodes listed. |
1642
|
|
|
|
|
|
|
|
1643
|
|
|
|
|
|
|
see also: count fold unfold |
1644
|
|
|
|
|
|
|
|
1645
|
|
|
|
|
|
|
END |
1646
|
|
|
|
|
|
|
|
1647
|
|
|
|
|
|
|
$HELP{'list'}=$HELP{'ls'}; |
1648
|
|
|
|
|
|
|
|
1649
|
|
|
|
|
|
|
$HELP{'canonical'}=[<<'END']; |
1650
|
|
|
|
|
|
|
usage: canonical [--comments|:c] [--filter|:f [xpath]] [[expression]] |
1651
|
|
|
|
|
|
|
|
1652
|
|
|
|
|
|
|
description: |
1653
|
|
|
|
|
|
|
This commands prints a canonical XML representing nodes |
1654
|
|
|
|
|
|
|
specified by its argument (or current node, if no argument is |
1655
|
|
|
|
|
|
|
given). |
1656
|
|
|
|
|
|
|
|
1657
|
|
|
|
|
|
|
'--comments' or ':c' removes comments from the resulting XML. |
1658
|
|
|
|
|
|
|
|
1659
|
|
|
|
|
|
|
'--filter' or ':f' can be used to filter the resulting XML so |
1660
|
|
|
|
|
|
|
that it only contains nodes explicitly included in the given |
1661
|
|
|
|
|
|
|
node-set. |
1662
|
|
|
|
|
|
|
|
1663
|
|
|
|
|
|
|
For details see "Canonical XML" or "Exclusive XML |
1664
|
|
|
|
|
|
|
Canonicalization" W3C recommendations. |
1665
|
|
|
|
|
|
|
|
1666
|
|
|
|
|
|
|
see also: ls |
1667
|
|
|
|
|
|
|
|
1668
|
|
|
|
|
|
|
END |
1669
|
|
|
|
|
|
|
|
1670
|
|
|
|
|
|
|
|
1671
|
|
|
|
|
|
|
$HELP{'count'}=[<<'END']; |
1672
|
|
|
|
|
|
|
usage: count [--quiet|:q] [xpath] |
1673
|
|
|
|
|
|
|
|
1674
|
|
|
|
|
|
|
description: |
1675
|
|
|
|
|
|
|
Calculates a given [expression] expression. If the result is a |
1676
|
|
|
|
|
|
|
node-list, print number of nodes in the node-list. If the |
1677
|
|
|
|
|
|
|
[expression] results in a boolean, numeric or literal value, |
1678
|
|
|
|
|
|
|
print the value. |
1679
|
|
|
|
|
|
|
|
1680
|
|
|
|
|
|
|
If '--quiet' or ':q' option is used, output is suppressed and |
1681
|
|
|
|
|
|
|
the value is returned. |
1682
|
|
|
|
|
|
|
|
1683
|
|
|
|
|
|
|
see also: get |
1684
|
|
|
|
|
|
|
|
1685
|
|
|
|
|
|
|
END |
1686
|
|
|
|
|
|
|
|
1687
|
|
|
|
|
|
|
|
1688
|
|
|
|
|
|
|
$HELP{'change-ns-uri'}=[<<'END']; |
1689
|
|
|
|
|
|
|
usage: change-ns-uri [expression] [[expression]] |
1690
|
|
|
|
|
|
|
|
1691
|
|
|
|
|
|
|
description: |
1692
|
|
|
|
|
|
|
This command takes one or two arguments. The first argument is |
1693
|
|
|
|
|
|
|
a new namespace URI and the second, optional, argument is a |
1694
|
|
|
|
|
|
|
namespace prefix. It changes the URI value of a namespace |
1695
|
|
|
|
|
|
|
declaration of the context node to the new value. If no prefix |
1696
|
|
|
|
|
|
|
is given, the change applies to a declaration on the context |
1697
|
|
|
|
|
|
|
node whose prefix equals to the prefix of the context node, |
1698
|
|
|
|
|
|
|
otherwise the change applies to a declaration with the given |
1699
|
|
|
|
|
|
|
prefix. |
1700
|
|
|
|
|
|
|
|
1701
|
|
|
|
|
|
|
see also: change-ns-prefix set-ns declare-ns namespaces |
1702
|
|
|
|
|
|
|
|
1703
|
|
|
|
|
|
|
END |
1704
|
|
|
|
|
|
|
|
1705
|
|
|
|
|
|
|
|
1706
|
|
|
|
|
|
|
$HELP{'change-ns-prefix'}=[<<'END']; |
1707
|
|
|
|
|
|
|
usage: change-ns-prefix [expression] [[expression]] |
1708
|
|
|
|
|
|
|
|
1709
|
|
|
|
|
|
|
description: |
1710
|
|
|
|
|
|
|
This command takes one or two arguments. The first argument is |
1711
|
|
|
|
|
|
|
a new prefix and the second, optional, argument is an old |
1712
|
|
|
|
|
|
|
namespace prefix. It changes the prefix of a namespace |
1713
|
|
|
|
|
|
|
declaration of the context node to the new value. If no old |
1714
|
|
|
|
|
|
|
prefix is given, the change applies to a declaration on the |
1715
|
|
|
|
|
|
|
context node whose prefix equals to the prefix of the context |
1716
|
|
|
|
|
|
|
node, otherwise the command changes the declaration with the |
1717
|
|
|
|
|
|
|
given old prefix. |
1718
|
|
|
|
|
|
|
|
1719
|
|
|
|
|
|
|
The command throws an exception if the new prefix is already |
1720
|
|
|
|
|
|
|
taken by some other declaration in the scope. |
1721
|
|
|
|
|
|
|
|
1722
|
|
|
|
|
|
|
see also: change-ns-uri set-ns declare-ns namespaces |
1723
|
|
|
|
|
|
|
|
1724
|
|
|
|
|
|
|
END |
1725
|
|
|
|
|
|
|
|
1726
|
|
|
|
|
|
|
|
1727
|
|
|
|
|
|
|
$HELP{'set-ns'}=[<<'END']; |
1728
|
|
|
|
|
|
|
usage: set-ns [:p|--prefix [expression]] [expression] |
1729
|
|
|
|
|
|
|
|
1730
|
|
|
|
|
|
|
description: |
1731
|
|
|
|
|
|
|
This command takes one argument, the namespace URI, possibly |
1732
|
|
|
|
|
|
|
accompanied by a prefix provided in the option '--prefix' |
1733
|
|
|
|
|
|
|
':p'; both these expressions are evaluated as names. The |
1734
|
|
|
|
|
|
|
command changes the namespace of the current element to a |
1735
|
|
|
|
|
|
|
given namespace URI. The current node must be in the scope of |
1736
|
|
|
|
|
|
|
a namespace declaration associating the namespace URI with a |
1737
|
|
|
|
|
|
|
prefix; if prefix option is given, then one of such |
1738
|
|
|
|
|
|
|
declarations must associate the particular given prefix with |
1739
|
|
|
|
|
|
|
the namespace URI. If this condition is not met or the current |
1740
|
|
|
|
|
|
|
node is neither element nor attribute, an error is issued. The |
1741
|
|
|
|
|
|
|
command also changes the prefix of the current element |
1742
|
|
|
|
|
|
|
accordingly. |
1743
|
|
|
|
|
|
|
|
1744
|
|
|
|
|
|
|
see also: declare-ns change-ns-uri change-ns-prefix namespaces |
1745
|
|
|
|
|
|
|
|
1746
|
|
|
|
|
|
|
END |
1747
|
|
|
|
|
|
|
|
1748
|
|
|
|
|
|
|
|
1749
|
|
|
|
|
|
|
$HELP{'declare-ns'}=[<<'END']; |
1750
|
|
|
|
|
|
|
usage: declare-ns [expression] [expression] |
1751
|
|
|
|
|
|
|
|
1752
|
|
|
|
|
|
|
description: |
1753
|
|
|
|
|
|
|
This command takes one or two arguments: prefix and URI, both |
1754
|
|
|
|
|
|
|
evaluated as names. It creates a namespace declaration of the |
1755
|
|
|
|
|
|
|
form 'xmlns:prefix="URI"' on the current node. The command |
1756
|
|
|
|
|
|
|
produces an error if the prefix is already declared in the |
1757
|
|
|
|
|
|
|
scope of the current node with a different namespace URI. |
1758
|
|
|
|
|
|
|
|
1759
|
|
|
|
|
|
|
see also: set-ns change-ns-uri change-ns-prefix namespaces |
1760
|
|
|
|
|
|
|
|
1761
|
|
|
|
|
|
|
END |
1762
|
|
|
|
|
|
|
|
1763
|
|
|
|
|
|
|
|
1764
|
|
|
|
|
|
|
$HELP{'set'}=[<<'END']; |
1765
|
|
|
|
|
|
|
usage: set [xpath] [[xpath]] |
1766
|
|
|
|
|
|
|
|
1767
|
|
|
|
|
|
|
description: |
1768
|
|
|
|
|
|
|
This command provides very easy way to create or modify |
1769
|
|
|
|
|
|
|
content of a document. It takes two XPath expressions. The |
1770
|
|
|
|
|
|
|
first one should be a node location path which specifies the |
1771
|
|
|
|
|
|
|
target node, the second is optional and provides new content |
1772
|
|
|
|
|
|
|
for the target node. If a node matches the first XPath |
1773
|
|
|
|
|
|
|
expression, then its content is replaced with the given value. |
1774
|
|
|
|
|
|
|
If no node matches, then XSH2 tries to magically extend the |
1775
|
|
|
|
|
|
|
current document by adding nodes in order to add missing steps |
1776
|
|
|
|
|
|
|
of the location path so as to make the expression match a |
1777
|
|
|
|
|
|
|
node. This node is then populated with a copy of the content |
1778
|
|
|
|
|
|
|
value (either text or, if the content [xpath] results in a |
1779
|
|
|
|
|
|
|
node-list and the target node is an element, nodes). |
1780
|
|
|
|
|
|
|
|
1781
|
|
|
|
|
|
|
Example: Try the following on an empty scratch document |
1782
|
|
|
|
|
|
|
|
1783
|
|
|
|
|
|
|
$scratch/> ls / |
1784
|
|
|
|
|
|
|
|
1785
|
|
|
|
|
|
|
$scratch/> set scratch/@say "hallo world" |
1786
|
|
|
|
|
|
|
|
1787
|
|
|
|
|
|
|
|
1788
|
|
|
|
|
|
|
$scratch/> set scratch/foo[2]/../foo[1]/following-sibling::bar/baz[3] "HALLO" |
1789
|
|
|
|
|
|
|
$scratch/> ls / |
1790
|
|
|
|
|
|
|
|
1791
|
|
|
|
|
|
|
|
1792
|
|
|
|
|
|
|
|
1793
|
|
|
|
|
|
|
|
1794
|
|
|
|
|
|
|
|
1795
|
|
|
|
|
|
|
|
1796
|
|
|
|
|
|
|
HALLO |
1797
|
|
|
|
|
|
|
|
1798
|
|
|
|
|
|
|
|
1799
|
|
|
|
|
|
|
|
1800
|
|
|
|
|
|
|
|
1801
|
|
|
|
|
|
|
Only a limited subset of XPath is currently supported by this |
1802
|
|
|
|
|
|
|
command. Namely, the XPath expression must be a location path |
1803
|
|
|
|
|
|
|
consisting of a /-separated sequence of one or more location |
1804
|
|
|
|
|
|
|
steps and new nodes can only be magically created along the |
1805
|
|
|
|
|
|
|
child, sibling, or attribute axes. The node-test part of the |
1806
|
|
|
|
|
|
|
expression can neither be a wildcard ('*', '@*', 'prefix:*', |
1807
|
|
|
|
|
|
|
...), nor the 'node()' function. If a namespace prefix is |
1808
|
|
|
|
|
|
|
used, then either the namespace must already be declared in |
1809
|
|
|
|
|
|
|
the document or registered with XSH. |
1810
|
|
|
|
|
|
|
|
1811
|
|
|
|
|
|
|
Location steps may contain arbitrary predicates (filters), |
1812
|
|
|
|
|
|
|
however, only a limited subset is supported for magically |
1813
|
|
|
|
|
|
|
created nodes. In particular, if a filter predicate of a |
1814
|
|
|
|
|
|
|
location step specifies a position of a node (e.g. with '[4]', |
1815
|
|
|
|
|
|
|
or '[position()>3]', etc), then the parser tries to |
1816
|
|
|
|
|
|
|
automatically create empty siblings nodes until it finally |
1817
|
|
|
|
|
|
|
creates one with for which the predicate is true. |
1818
|
|
|
|
|
|
|
|
1819
|
|
|
|
|
|
|
Note, that this command only processes one location step at a |
1820
|
|
|
|
|
|
|
time and always picks the first matching node. So, expressions |
1821
|
|
|
|
|
|
|
like '/root/a/b' are treated as '/root/a[1]/b[1]'. This means |
1822
|
|
|
|
|
|
|
that an expression '/root/a/b' will magically create element |
1823
|
|
|
|
|
|
|
'' in a first matching '' even if some following '' |
1824
|
|
|
|
|
|
|
already contains a ''. |
1825
|
|
|
|
|
|
|
|
1826
|
|
|
|
|
|
|
To prevent this, either explicitly state that 'b' must exist |
1827
|
|
|
|
|
|
|
with e.g. '/root/a[b]/b' or make the corresponding element |
1828
|
|
|
|
|
|
|
'' the context node and use a relative location path: |
1829
|
|
|
|
|
|
|
|
1830
|
|
|
|
|
|
|
Example: |
1831
|
|
|
|
|
|
|
for /root/a/b set b 'foo' |
1832
|
|
|
|
|
|
|
|
1833
|
|
|
|
|
|
|
END |
1834
|
|
|
|
|
|
|
|
1835
|
|
|
|
|
|
|
|
1836
|
|
|
|
|
|
|
$HELP{'get'}=[<<'END']; |
1837
|
|
|
|
|
|
|
usage: get [expression] |
1838
|
|
|
|
|
|
|
|
1839
|
|
|
|
|
|
|
aliases: exp expr |
1840
|
|
|
|
|
|
|
|
1841
|
|
|
|
|
|
|
description: |
1842
|
|
|
|
|
|
|
Calculate a given [expression] and return the value. |
1843
|
|
|
|
|
|
|
|
1844
|
|
|
|
|
|
|
see also: count |
1845
|
|
|
|
|
|
|
|
1846
|
|
|
|
|
|
|
END |
1847
|
|
|
|
|
|
|
|
1848
|
|
|
|
|
|
|
$HELP{'exp'}=$HELP{'get'}; |
1849
|
|
|
|
|
|
|
$HELP{'expr'}=$HELP{'get'}; |
1850
|
|
|
|
|
|
|
|
1851
|
|
|
|
|
|
|
$HELP{'perl-code'}=[<<'END']; |
1852
|
|
|
|
|
|
|
Perl-code argument type |
1853
|
|
|
|
|
|
|
|
1854
|
|
|
|
|
|
|
description: |
1855
|
|
|
|
|
|
|
A block of Perl code enclosed in braces. All XSH2 variables |
1856
|
|
|
|
|
|
|
are transparently accessible from the Perl code as well. |
1857
|
|
|
|
|
|
|
|
1858
|
|
|
|
|
|
|
For more information about embedded Perl code in XSH2, |
1859
|
|
|
|
|
|
|
predefined functions etc., see [Perl_shell]. |
1860
|
|
|
|
|
|
|
|
1861
|
|
|
|
|
|
|
Example: |
1862
|
|
|
|
|
|
|
xsh> $i={ "foo" }; |
1863
|
|
|
|
|
|
|
xsh> perl { echo "$i-bar\n"; } # prints foo-bar |
1864
|
|
|
|
|
|
|
xsh> echo { "$i-bar" } # very much the same as above |
1865
|
|
|
|
|
|
|
|
1866
|
|
|
|
|
|
|
END |
1867
|
|
|
|
|
|
|
|
1868
|
|
|
|
|
|
|
|
1869
|
|
|
|
|
|
|
$HELP{'perl'}=[<<'END']; |
1870
|
|
|
|
|
|
|
usage: perl [perl-code] |
1871
|
|
|
|
|
|
|
|
1872
|
|
|
|
|
|
|
description: |
1873
|
|
|
|
|
|
|
Evaluate a given perl expression and return the result. |
1874
|
|
|
|
|
|
|
|
1875
|
|
|
|
|
|
|
see also: count |
1876
|
|
|
|
|
|
|
|
1877
|
|
|
|
|
|
|
END |
1878
|
|
|
|
|
|
|
|
1879
|
|
|
|
|
|
|
|
1880
|
|
|
|
|
|
|
$HELP{'remove'}=[<<'END']; |
1881
|
|
|
|
|
|
|
usage: remove [expression] |
1882
|
|
|
|
|
|
|
|
1883
|
|
|
|
|
|
|
aliases: rm prune delete del |
1884
|
|
|
|
|
|
|
|
1885
|
|
|
|
|
|
|
description: |
1886
|
|
|
|
|
|
|
Unlink all nodes in a given node-list from their respective |
1887
|
|
|
|
|
|
|
documents. Nodes, which are neither attached to a document or |
1888
|
|
|
|
|
|
|
stored in a variable are automatically garbage-collected. |
1889
|
|
|
|
|
|
|
|
1890
|
|
|
|
|
|
|
Returns a number of nodes removed. |
1891
|
|
|
|
|
|
|
|
1892
|
|
|
|
|
|
|
Example: Get rid of all evil creatures. |
1893
|
|
|
|
|
|
|
|
1894
|
|
|
|
|
|
|
xsh> del //creature[@manner='evil'] |
1895
|
|
|
|
|
|
|
|
1896
|
|
|
|
|
|
|
END |
1897
|
|
|
|
|
|
|
|
1898
|
|
|
|
|
|
|
$HELP{'rm'}=$HELP{'remove'}; |
1899
|
|
|
|
|
|
|
$HELP{'prune'}=$HELP{'remove'}; |
1900
|
|
|
|
|
|
|
$HELP{'delete'}=$HELP{'remove'}; |
1901
|
|
|
|
|
|
|
$HELP{'del'}=$HELP{'remove'}; |
1902
|
|
|
|
|
|
|
|
1903
|
|
|
|
|
|
|
$HELP{'print'}=[<<'END']; |
1904
|
|
|
|
|
|
|
usage: print [--nonl|:n] [--nospace|:s] [--stderr|:e] [expression] [[expression] ...] |
1905
|
|
|
|
|
|
|
|
1906
|
|
|
|
|
|
|
aliases: echo |
1907
|
|
|
|
|
|
|
|
1908
|
|
|
|
|
|
|
description: |
1909
|
|
|
|
|
|
|
Evaluate given expression(s) and print the results (separated |
1910
|
|
|
|
|
|
|
by a single space character). Expressions not containing any |
1911
|
|
|
|
|
|
|
special characters, such as brackets, quotes, $, or @ are |
1912
|
|
|
|
|
|
|
considered as bare words and evaluate to themselves. |
1913
|
|
|
|
|
|
|
|
1914
|
|
|
|
|
|
|
'--nonl' or ':n' can be used to avoid printing a trailing |
1915
|
|
|
|
|
|
|
new-line. |
1916
|
|
|
|
|
|
|
|
1917
|
|
|
|
|
|
|
'--nospace' or ':s' suppresses printing additional spaces |
1918
|
|
|
|
|
|
|
between individual arguments. |
1919
|
|
|
|
|
|
|
|
1920
|
|
|
|
|
|
|
'--stderr' or ':e' causes the command to print on standard |
1921
|
|
|
|
|
|
|
error output. |
1922
|
|
|
|
|
|
|
|
1923
|
|
|
|
|
|
|
Example: |
1924
|
|
|
|
|
|
|
print foo bar; # prints "foo bar" |
1925
|
|
|
|
|
|
|
print "foo bar"; # prints "foo bar" |
1926
|
|
|
|
|
|
|
|
1927
|
|
|
|
|
|
|
END |
1928
|
|
|
|
|
|
|
|
1929
|
|
|
|
|
|
|
$HELP{'echo'}=$HELP{'print'}; |
1930
|
|
|
|
|
|
|
|
1931
|
|
|
|
|
|
|
$HELP{'sort'}=[<<'END']; |
1932
|
|
|
|
|
|
|
usage: $result := sort [ --key|:k [expression] ] |
1933
|
|
|
|
|
|
|
--compare|:c [perl-code] [expression] |
1934
|
|
|
|
|
|
|
$result := sort [ --key|:k [expression] ] |
1935
|
|
|
|
|
|
|
[ --numeric|:n ] [ --descending|:d ] [ --locale|:l] [expression] |
1936
|
|
|
|
|
|
|
|
1937
|
|
|
|
|
|
|
description: |
1938
|
|
|
|
|
|
|
This command sorts a given node-list, returning a node-list |
1939
|
|
|
|
|
|
|
ordered according to a given key and ordering function. |
1940
|
|
|
|
|
|
|
|
1941
|
|
|
|
|
|
|
'--key|:k' followed by an expression specifies the key to be |
1942
|
|
|
|
|
|
|
computed for each member of the node-list and the result used |
1943
|
|
|
|
|
|
|
as the sorting key. If omitted, keys are created by converting |
1944
|
|
|
|
|
|
|
the nodes to string as if XPath expression 'string(.)' was |
1945
|
|
|
|
|
|
|
used. |
1946
|
|
|
|
|
|
|
|
1947
|
|
|
|
|
|
|
'--numeric|:n' specifies, that keys should be compared by |
1948
|
|
|
|
|
|
|
their numerical values (the default is string comparison). |
1949
|
|
|
|
|
|
|
|
1950
|
|
|
|
|
|
|
'--descending|:d' specifies, that the result should be ordered |
1951
|
|
|
|
|
|
|
in descending order (default is ascending). |
1952
|
|
|
|
|
|
|
|
1953
|
|
|
|
|
|
|
'--locale|:l' forces using current locale settings for string |
1954
|
|
|
|
|
|
|
comparison (default is no locale). |
1955
|
|
|
|
|
|
|
|
1956
|
|
|
|
|
|
|
'--compare' argument followed by a [perl-code] allows to |
1957
|
|
|
|
|
|
|
define a custom comparison method in a similar way to Perl |
1958
|
|
|
|
|
|
|
'sort' command. The keys to be compared are passed to the code |
1959
|
|
|
|
|
|
|
in variables '$a' and '$b'. The code is supposed to return 1 |
1960
|
|
|
|
|
|
|
if the key in '$a' is greater than '$b', 0 if the keys are |
1961
|
|
|
|
|
|
|
equal and '-1' if '$a' is less than '$b', depending on how the |
1962
|
|
|
|
|
|
|
corresponding elements are to be ordered. It is a run-time |
1963
|
|
|
|
|
|
|
error to use '--compare' together with either '--numeric' or |
1964
|
|
|
|
|
|
|
'--descending'. |
1965
|
|
|
|
|
|
|
|
1966
|
|
|
|
|
|
|
Example: Case-insensitive sort of a given node-list |
1967
|
|
|
|
|
|
|
|
1968
|
|
|
|
|
|
|
$ordered := sort --key xsh:lc(.) $unordered; |
1969
|
|
|
|
|
|
|
|
1970
|
|
|
|
|
|
|
Example: Reorder creature elements by name attribute in ascending order |
1971
|
|
|
|
|
|
|
using Czech locale settings |
1972
|
|
|
|
|
|
|
|
1973
|
|
|
|
|
|
|
perl { |
1974
|
|
|
|
|
|
|
# setup locale collating function |
1975
|
|
|
|
|
|
|
# Note, that the collating function must be UTF8 aware. |
1976
|
|
|
|
|
|
|
use POSIX qw(locale_h); |
1977
|
|
|
|
|
|
|
setlocale(LC_COLLATE,'cs_CZ.UTF-8'); |
1978
|
|
|
|
|
|
|
}; |
1979
|
|
|
|
|
|
|
|
1980
|
|
|
|
|
|
|
xmove &{ sort :k@name :l * } into /middle-earth[1]/creatures; |
1981
|
|
|
|
|
|
|
|
1982
|
|
|
|
|
|
|
Example: Sort a node-list by a pre-computed score (Perl-based sort) |
1983
|
|
|
|
|
|
|
|
1984
|
|
|
|
|
|
|
$results := sort --numeric --descending --key { $scores{literal('@name')} } $players; |
1985
|
|
|
|
|
|
|
|
1986
|
|
|
|
|
|
|
END |
1987
|
|
|
|
|
|
|
|
1988
|
|
|
|
|
|
|
|
1989
|
|
|
|
|
|
|
$HELP{'map'}=[<<'END']; |
1990
|
|
|
|
|
|
|
usage: map [expression] [expression] |
1991
|
|
|
|
|
|
|
|
1992
|
|
|
|
|
|
|
description: |
1993
|
|
|
|
|
|
|
NOTE: THE SEMANTICS OF COMMAND HAS CHANGED IN 2.1.0 |
1994
|
|
|
|
|
|
|
|
1995
|
|
|
|
|
|
|
This command provides an easy way to transform node's data |
1996
|
|
|
|
|
|
|
(content) using arbitrary expression. It takes two arguments: |
1997
|
|
|
|
|
|
|
a mapping expression and a node-list. |
1998
|
|
|
|
|
|
|
|
1999
|
|
|
|
|
|
|
First the second argument is evaluated to a node-list. For |
2000
|
|
|
|
|
|
|
each of the nodes, the mapping expression is evaluated and the |
2001
|
|
|
|
|
|
|
result is used to replace the original content of the node. |
2002
|
|
|
|
|
|
|
The node is made the context node for the time of evaluation |
2003
|
|
|
|
|
|
|
of the mapping expression. Moreover, if the expression is a |
2004
|
|
|
|
|
|
|
Perl code, it gets the original text content in the variable |
2005
|
|
|
|
|
|
|
'$_'. |
2006
|
|
|
|
|
|
|
|
2007
|
|
|
|
|
|
|
Note that if the processed node is an element than the mapping |
2008
|
|
|
|
|
|
|
expression may even produce nodes which are then copied into |
2009
|
|
|
|
|
|
|
the element discarding any previous content of the element. |
2010
|
|
|
|
|
|
|
|
2011
|
|
|
|
|
|
|
If the mapping expression returns an undefined value for a |
2012
|
|
|
|
|
|
|
node, then its content is kept untouched. |
2013
|
|
|
|
|
|
|
|
2014
|
|
|
|
|
|
|
'--in-place' (':i') flag: if the expression is a Perl code, |
2015
|
|
|
|
|
|
|
then it is sometimes convenient to change the value in place. |
2016
|
|
|
|
|
|
|
In that case use this flag to indicate that the result should |
2017
|
|
|
|
|
|
|
to be taken from the '$_' variable rather than from the value |
2018
|
|
|
|
|
|
|
of the expression itself. Without this flag, '$_' is |
2019
|
|
|
|
|
|
|
read-only. |
2020
|
|
|
|
|
|
|
|
2021
|
|
|
|
|
|
|
'--reverse' (':r') flag instruct the map to process the |
2022
|
|
|
|
|
|
|
nodelist in reversed order. |
2023
|
|
|
|
|
|
|
|
2024
|
|
|
|
|
|
|
Example: Capitalizes all hobbit names |
2025
|
|
|
|
|
|
|
|
2026
|
|
|
|
|
|
|
map { ucfirst($_) } //hobbit/@name; |
2027
|
|
|
|
|
|
|
|
2028
|
|
|
|
|
|
|
Example: Changes Goblins to Orcs in all hobbit tales (\b matches word |
2029
|
|
|
|
|
|
|
boundary). |
2030
|
|
|
|
|
|
|
|
2031
|
|
|
|
|
|
|
map :i { s/\bgoblin\b/orc/gi } //hobbit/tale/text(); |
2032
|
|
|
|
|
|
|
|
2033
|
|
|
|
|
|
|
Example: Recompute column sums in the last row of row-oriented table |
2034
|
|
|
|
|
|
|
|
2035
|
|
|
|
|
|
|
map sum(/table/row[position()
|
2036
|
|
|
|
|
|
|
cell[count(xsh:current()/preceding-sibling::cell)+1]) |
2037
|
|
|
|
|
|
|
/table/row[last()]/cell; |
2038
|
|
|
|
|
|
|
|
2039
|
|
|
|
|
|
|
Example: The following commands do all about the same: |
2040
|
|
|
|
|
|
|
|
2041
|
|
|
|
|
|
|
wrap --inner Z //*; |
2042
|
|
|
|
|
|
|
map --reverse xsh:parse(concat("",xsh:serialize(node()),"")) //*; |
2043
|
|
|
|
|
|
|
map xsh:parse(concat("",xsh:serialize(node()),"")) { reverse xpath('//*') }; |
2044
|
|
|
|
|
|
|
|
2045
|
|
|
|
|
|
|
Note that in the last example we use ':r' (or Perl 'reverse' |
2046
|
|
|
|
|
|
|
function) to reverse the node list order so that child nodes |
2047
|
|
|
|
|
|
|
get processed before their parents. Otherwise, the child nodes |
2048
|
|
|
|
|
|
|
would be replaced by parent's new content before the |
2049
|
|
|
|
|
|
|
processing could reach them. |
2050
|
|
|
|
|
|
|
|
2051
|
|
|
|
|
|
|
see also: rename |
2052
|
|
|
|
|
|
|
|
2053
|
|
|
|
|
|
|
END |
2054
|
|
|
|
|
|
|
|
2055
|
|
|
|
|
|
|
|
2056
|
|
|
|
|
|
|
$HELP{'rename'}=[<<'END']; |
2057
|
|
|
|
|
|
|
usage: rename [nodename] [expression] |
2058
|
|
|
|
|
|
|
|
2059
|
|
|
|
|
|
|
description: |
2060
|
|
|
|
|
|
|
NOTE: THE SEMANTICS OF COMMAND HAS CHANGED IN 2.1.0 |
2061
|
|
|
|
|
|
|
|
2062
|
|
|
|
|
|
|
This command is very similar to the [map] command, except that |
2063
|
|
|
|
|
|
|
it operates on nodes' names rather than their content. It |
2064
|
|
|
|
|
|
|
changes name of every element, attribute or |
2065
|
|
|
|
|
|
|
processing-instruction contained in the node-list specified in |
2066
|
|
|
|
|
|
|
the second argument [expression], according to the value of |
2067
|
|
|
|
|
|
|
the [nodename] expression, which is evaluated in the context |
2068
|
|
|
|
|
|
|
of each node in turn. |
2069
|
|
|
|
|
|
|
|
2070
|
|
|
|
|
|
|
If the [nodename] is a Perl expression, then the name of the |
2071
|
|
|
|
|
|
|
node is also stored into Perl's '$_' variable prior to |
2072
|
|
|
|
|
|
|
evaluation. |
2073
|
|
|
|
|
|
|
|
2074
|
|
|
|
|
|
|
The flag '--in-place' (':i') can be used to indicate that the |
2075
|
|
|
|
|
|
|
new name should be collected from the '$_' variable rather |
2076
|
|
|
|
|
|
|
than from the result of the expression itself. |
2077
|
|
|
|
|
|
|
|
2078
|
|
|
|
|
|
|
The '--namespace' (':n') argument may be used to provide |
2079
|
|
|
|
|
|
|
namespace for the renamed nodes. |
2080
|
|
|
|
|
|
|
|
2081
|
|
|
|
|
|
|
'--reverse' (':r') flag instruct the map to process the |
2082
|
|
|
|
|
|
|
nodelist in reversed order. |
2083
|
|
|
|
|
|
|
|
2084
|
|
|
|
|
|
|
Note: if the expression [nodename] returns an undefined value |
2085
|
|
|
|
|
|
|
for a particular node, the node's original name and namespace |
2086
|
|
|
|
|
|
|
are preserved. |
2087
|
|
|
|
|
|
|
|
2088
|
|
|
|
|
|
|
Example: Renames all Hobbits to Halflings |
2089
|
|
|
|
|
|
|
|
2090
|
|
|
|
|
|
|
xsh> rename halfling //hobbit |
2091
|
|
|
|
|
|
|
|
2092
|
|
|
|
|
|
|
Example: Make all elements and attributes uppercase (yack!) |
2093
|
|
|
|
|
|
|
|
2094
|
|
|
|
|
|
|
xsh> rename { uc } (//*|//@*) |
2095
|
|
|
|
|
|
|
|
2096
|
|
|
|
|
|
|
Example: Substitute dashes with underscores in all node names |
2097
|
|
|
|
|
|
|
|
2098
|
|
|
|
|
|
|
xsh> rename :i { s/-/_/g } (//*|//@*) |
2099
|
|
|
|
|
|
|
|
2100
|
|
|
|
|
|
|
Example: Make all elements start with the name of their parents |
2101
|
|
|
|
|
|
|
|
2102
|
|
|
|
|
|
|
xsh> rename concat(local-name(parent::*),'.',local-name(.)) //*[parent::*] |
2103
|
|
|
|
|
|
|
|
2104
|
|
|
|
|
|
|
see also: map |
2105
|
|
|
|
|
|
|
|
2106
|
|
|
|
|
|
|
END |
2107
|
|
|
|
|
|
|
|
2108
|
|
|
|
|
|
|
|
2109
|
|
|
|
|
|
|
$HELP{'hash'}=[<<'END']; |
2110
|
|
|
|
|
|
|
usage: $hash := hash [expression] [expression] |
2111
|
|
|
|
|
|
|
|
2112
|
|
|
|
|
|
|
description: |
2113
|
|
|
|
|
|
|
This command takes two arguments: an expression computing a |
2114
|
|
|
|
|
|
|
key from a given node (1st argument) and a node-set (2nd |
2115
|
|
|
|
|
|
|
argument). For each node in the node-set, the key value is |
2116
|
|
|
|
|
|
|
computed and the node is stored under the given key in the |
2117
|
|
|
|
|
|
|
resulting hash. For a given key, the value stored in the hash |
2118
|
|
|
|
|
|
|
table is a node-list consisting of all nodes for which the 1st |
2119
|
|
|
|
|
|
|
expression evaluated to an object string-wise equal to the |
2120
|
|
|
|
|
|
|
key. It is therefore possible to index more than one node |
2121
|
|
|
|
|
|
|
under the same key. |
2122
|
|
|
|
|
|
|
|
2123
|
|
|
|
|
|
|
The XPath function 'xsh:lookup(varname,key)' can be used to |
2124
|
|
|
|
|
|
|
retrieve values from hashes in XPath expressions. |
2125
|
|
|
|
|
|
|
|
2126
|
|
|
|
|
|
|
Example: Index books by author |
2127
|
|
|
|
|
|
|
|
2128
|
|
|
|
|
|
|
my $books_by_author := hash concat(author/firstname," ",author/surname) //book; |
2129
|
|
|
|
|
|
|
|
2130
|
|
|
|
|
|
|
Example: Lookup books by Jack London. |
2131
|
|
|
|
|
|
|
|
2132
|
|
|
|
|
|
|
ls { $books_by_author->{'Jack London'} }; |
2133
|
|
|
|
|
|
|
ls xsh:lookup('books_by_author','Jack London'); |
2134
|
|
|
|
|
|
|
|
2135
|
|
|
|
|
|
|
see also: xsh:lookup |
2136
|
|
|
|
|
|
|
|
2137
|
|
|
|
|
|
|
END |
2138
|
|
|
|
|
|
|
|
2139
|
|
|
|
|
|
|
|
2140
|
|
|
|
|
|
|
$HELP{'close'}=[<<'END']; |
2141
|
|
|
|
|
|
|
usage: close [[document]] |
2142
|
|
|
|
|
|
|
|
2143
|
|
|
|
|
|
|
description: |
2144
|
|
|
|
|
|
|
Close a given [document] (or, if called with no argument, the |
2145
|
|
|
|
|
|
|
current document) by trying to remove all references from XSH2 |
2146
|
|
|
|
|
|
|
variables to nodes belonging to the document. If no references |
2147
|
|
|
|
|
|
|
to the document are left, the garbage-collector destroys the |
2148
|
|
|
|
|
|
|
DOM tree and frees the memory it occupied for later reuse |
2149
|
|
|
|
|
|
|
(depending on architecture, this may or may not give the |
2150
|
|
|
|
|
|
|
allocated memory back to the system). |
2151
|
|
|
|
|
|
|
|
2152
|
|
|
|
|
|
|
END |
2153
|
|
|
|
|
|
|
|
2154
|
|
|
|
|
|
|
|
2155
|
|
|
|
|
|
|
$HELP{'index'}=[<<'END']; |
2156
|
|
|
|
|
|
|
usage: index [[document]] |
2157
|
|
|
|
|
|
|
|
2158
|
|
|
|
|
|
|
description: |
2159
|
|
|
|
|
|
|
This command makes 'libxml2' library to remember |
2160
|
|
|
|
|
|
|
document-order position of every element node in the |
2161
|
|
|
|
|
|
|
[document]. Such indexation makes XPath queries considerably |
2162
|
|
|
|
|
|
|
faster on large documents (with thousands of nodes). The |
2163
|
|
|
|
|
|
|
command should only be used on documents which don't change; |
2164
|
|
|
|
|
|
|
modifying an indexed document might possibly lead to |
2165
|
|
|
|
|
|
|
non-conformant behavior of later XPath queries on the |
2166
|
|
|
|
|
|
|
document. |
2167
|
|
|
|
|
|
|
|
2168
|
|
|
|
|
|
|
END |
2169
|
|
|
|
|
|
|
|
2170
|
|
|
|
|
|
|
|
2171
|
|
|
|
|
|
|
$HELP{'open'}=[<<'END']; |
2172
|
|
|
|
|
|
|
usage: $doc := open [--format|:F html|xml|docbook] |
2173
|
|
|
|
|
|
|
[--file|:f | --pipe|:p | --string|:s] |
2174
|
|
|
|
|
|
|
[--switch-to|:w | --no-switch-to|:W] |
2175
|
|
|
|
|
|
|
[--validate|:v | --no-validate|:V] |
2176
|
|
|
|
|
|
|
[--recover|:r | --no-recover|:R] |
2177
|
|
|
|
|
|
|
[--expand-entities|:e | --no-expand-entities|:E] |
2178
|
|
|
|
|
|
|
[--xinclude|:x | --no-xinclude|:X] |
2179
|
|
|
|
|
|
|
[--keep-blanks|:b | --no-keep-blanks|:B] |
2180
|
|
|
|
|
|
|
[--pedantic|:n | --no-pedantic|:N] |
2181
|
|
|
|
|
|
|
[--load-ext-dtd|:d | --no-load-ext-dtd|:D] |
2182
|
|
|
|
|
|
|
[--complete-attributes|:a | --no-complete-attributes|:A] |
2183
|
|
|
|
|
|
|
[expression] |
2184
|
|
|
|
|
|
|
|
2185
|
|
|
|
|
|
|
description: |
2186
|
|
|
|
|
|
|
Parse a XML, HTML or SGML DOCBOOK document from a file or URL, |
2187
|
|
|
|
|
|
|
command output or string and return a node-set consisting of |
2188
|
|
|
|
|
|
|
the root of the resulting DOM tree. |
2189
|
|
|
|
|
|
|
|
2190
|
|
|
|
|
|
|
'--format' (':F') option may be used to specify file format. |
2191
|
|
|
|
|
|
|
Possible values are 'xml' (default), 'html', and 'docbook'. |
2192
|
|
|
|
|
|
|
Note, however, that the support for parsing 'DocBook' SGML |
2193
|
|
|
|
|
|
|
files has been deprecated in recent 'libxml2' versions. |
2194
|
|
|
|
|
|
|
|
2195
|
|
|
|
|
|
|
'--file' (':f') instructs the parser to consider a given |
2196
|
|
|
|
|
|
|
[expression] as a file name or URL. |
2197
|
|
|
|
|
|
|
|
2198
|
|
|
|
|
|
|
'--pipe' (':p') instructs the parser to consider a given |
2199
|
|
|
|
|
|
|
[expression] as a system command and parse its output. |
2200
|
|
|
|
|
|
|
|
2201
|
|
|
|
|
|
|
'--string' (':s') instructs the parser to consider a given |
2202
|
|
|
|
|
|
|
[expression] as a string of XML or HTML to parse. |
2203
|
|
|
|
|
|
|
|
2204
|
|
|
|
|
|
|
'--switch-to' (':w') and '--no-switch-to' (':W') control |
2205
|
|
|
|
|
|
|
whether the new document's root should become current node. |
2206
|
|
|
|
|
|
|
These option override current global setting of |
2207
|
|
|
|
|
|
|
[switch-to-new-documents]. |
2208
|
|
|
|
|
|
|
|
2209
|
|
|
|
|
|
|
'--validate' (':v') and '--no-validate' (':V') turn on/off |
2210
|
|
|
|
|
|
|
DTD-validation of the parsed document. These option override |
2211
|
|
|
|
|
|
|
current global setting of [validation]. |
2212
|
|
|
|
|
|
|
|
2213
|
|
|
|
|
|
|
'--recover' (':r') and '--no-recover' (':R') turn on/off |
2214
|
|
|
|
|
|
|
parser's ability to recover from non-fatal errors. These |
2215
|
|
|
|
|
|
|
option override current global setting of [recovering]. |
2216
|
|
|
|
|
|
|
|
2217
|
|
|
|
|
|
|
'--expand-entities' (':e') and '--no-expand-entities' (':E') |
2218
|
|
|
|
|
|
|
turn on/off entity expansion, overriding current global |
2219
|
|
|
|
|
|
|
setting of [parser-expands-entities]. |
2220
|
|
|
|
|
|
|
|
2221
|
|
|
|
|
|
|
'--xinclude' (':x') and '--no-xinclude' (':X') turn on/off |
2222
|
|
|
|
|
|
|
XInclude processing, overriding current global settings of |
2223
|
|
|
|
|
|
|
[parser-expands-xinclude]. |
2224
|
|
|
|
|
|
|
|
2225
|
|
|
|
|
|
|
'--keep-blanks' (':b') and '--no-keep-blanks' (':B') control |
2226
|
|
|
|
|
|
|
whether the parser should preserve so called ignorable |
2227
|
|
|
|
|
|
|
whitespace. These option override current global setting of |
2228
|
|
|
|
|
|
|
[keep-blanks]. |
2229
|
|
|
|
|
|
|
|
2230
|
|
|
|
|
|
|
'--pedantic' (':n') and '--no-pedantic' (':N') turn on/off |
2231
|
|
|
|
|
|
|
pedantic parser flag. |
2232
|
|
|
|
|
|
|
|
2233
|
|
|
|
|
|
|
'--load-ext-dtd' (':d') and '--no-load-ext-dtd' (':D') control |
2234
|
|
|
|
|
|
|
whether the external DTD subset should be loaded with the |
2235
|
|
|
|
|
|
|
document. These option override current global setting of |
2236
|
|
|
|
|
|
|
[load-ext-dtd]. |
2237
|
|
|
|
|
|
|
|
2238
|
|
|
|
|
|
|
'--complete-attributes' (':a') and '--no-complete-attributes' |
2239
|
|
|
|
|
|
|
(':A') turn on/off parse-time default attribute completion |
2240
|
|
|
|
|
|
|
based on default values specified in the DTD. These option |
2241
|
|
|
|
|
|
|
override current global setting of |
2242
|
|
|
|
|
|
|
[parser-completes-attributes]. |
2243
|
|
|
|
|
|
|
|
2244
|
|
|
|
|
|
|
Example: |
2245
|
|
|
|
|
|
|
$scratch/> $x := open mydoc.xml # open an XML document |
2246
|
|
|
|
|
|
|
|
2247
|
|
|
|
|
|
|
# open a HTML document from the Internet |
2248
|
|
|
|
|
|
|
$h:=open --format html "http://www.google.com/?q=xsh" |
2249
|
|
|
|
|
|
|
# quote file name if it contains whitespace |
2250
|
|
|
|
|
|
|
$y := open "document with a long name with spaces.xml" |
2251
|
|
|
|
|
|
|
|
2252
|
|
|
|
|
|
|
# use --format html or --format docbook to load these types |
2253
|
|
|
|
|
|
|
$z := open --format html index.htm |
2254
|
|
|
|
|
|
|
|
2255
|
|
|
|
|
|
|
# use --pipe flag to read output of a command |
2256
|
|
|
|
|
|
|
$z := open --format html --pipe 'wget -O - xsh.sourceforge.net/index.html' |
2257
|
|
|
|
|
|
|
|
2258
|
|
|
|
|
|
|
# use document variable to restrict XPath search to a |
2259
|
|
|
|
|
|
|
# given document |
2260
|
|
|
|
|
|
|
ls $z//chapter/title |
2261
|
|
|
|
|
|
|
|
2262
|
|
|
|
|
|
|
END |
2263
|
|
|
|
|
|
|
|
2264
|
|
|
|
|
|
|
|
2265
|
|
|
|
|
|
|
$HELP{'create'}=[<<'END']; |
2266
|
|
|
|
|
|
|
usage: $doc := create [nodename]|[expression] |
2267
|
|
|
|
|
|
|
|
2268
|
|
|
|
|
|
|
aliases: new |
2269
|
|
|
|
|
|
|
|
2270
|
|
|
|
|
|
|
description: |
2271
|
|
|
|
|
|
|
Returns a new document object. The argument must evaluate |
2272
|
|
|
|
|
|
|
either to a valid element name (possibly followed by some |
2273
|
|
|
|
|
|
|
attribute declarations) to be used for the document element, |
2274
|
|
|
|
|
|
|
or to a well-formed XML string. |
2275
|
|
|
|
|
|
|
|
2276
|
|
|
|
|
|
|
Unless [switch-to-new-documents] option is turned off, this |
2277
|
|
|
|
|
|
|
command also changes current node to the new document. |
2278
|
|
|
|
|
|
|
|
2279
|
|
|
|
|
|
|
Example: |
2280
|
|
|
|
|
|
|
$scratch/> $t1 := create root |
2281
|
|
|
|
|
|
|
$t1> ls $t1 |
2282
|
|
|
|
|
|
|
|
2283
|
|
|
|
|
|
|
|
2284
|
|
|
|
|
|
|
|
2285
|
|
|
|
|
|
|
$t1> $t2 := create "root id='r1'" |
2286
|
|
|
|
|
|
|
$t2> ls $t2 |
2287
|
|
|
|
|
|
|
|
2288
|
|
|
|
|
|
|
|
2289
|
|
|
|
|
|
|
|
2290
|
|
|
|
|
|
|
$t2> create "Just a test" |
2291
|
|
|
|
|
|
|
/> ls / |
2292
|
|
|
|
|
|
|
|
2293
|
|
|
|
|
|
|
Just a test |
2294
|
|
|
|
|
|
|
|
2295
|
|
|
|
|
|
|
see also: open clone |
2296
|
|
|
|
|
|
|
|
2297
|
|
|
|
|
|
|
END |
2298
|
|
|
|
|
|
|
|
2299
|
|
|
|
|
|
|
$HELP{'new'}=$HELP{'create'}; |
2300
|
|
|
|
|
|
|
|
2301
|
|
|
|
|
|
|
$HELP{'save'}=[<<'END']; |
2302
|
|
|
|
|
|
|
usage: save [--format|:F html|xml] [--xinclude|:x] |
2303
|
|
|
|
|
|
|
[--file|:f [filename] | |
2304
|
|
|
|
|
|
|
--pipe|:p [filename] | |
2305
|
|
|
|
|
|
|
--string|:s | |
2306
|
|
|
|
|
|
|
--print|:r ] |
2307
|
|
|
|
|
|
|
[--subtree|:S] |
2308
|
|
|
|
|
|
|
[--indent|:i | --no-indent|:I] |
2309
|
|
|
|
|
|
|
[--skip-dtd|:d | --no-skip-dtd|:D] |
2310
|
|
|
|
|
|
|
[--skip-empty-tags|:t | --no-skip-empty-tags|:T] |
2311
|
|
|
|
|
|
|
[--skip-xmldecl|:x] |
2312
|
|
|
|
|
|
|
[--encoding|:e [encoding]] |
2313
|
|
|
|
|
|
|
[document] |
2314
|
|
|
|
|
|
|
|
2315
|
|
|
|
|
|
|
description: |
2316
|
|
|
|
|
|
|
This takes a given [document], serializes it to XML or HTML |
2317
|
|
|
|
|
|
|
and either saves the result to its original file or another |
2318
|
|
|
|
|
|
|
file (default), pipes it to an external command, prints it on |
2319
|
|
|
|
|
|
|
standard output, or simply returns it. Without arguments it |
2320
|
|
|
|
|
|
|
simply saves current document to its original file. |
2321
|
|
|
|
|
|
|
|
2322
|
|
|
|
|
|
|
'--file|:f' option may be used to specify an output file-name. |
2323
|
|
|
|
|
|
|
By default, the original document's file-name is used. |
2324
|
|
|
|
|
|
|
|
2325
|
|
|
|
|
|
|
'--pipe|:p' option specifies, that the output should be piped |
2326
|
|
|
|
|
|
|
to an external command specified as the option's argument. |
2327
|
|
|
|
|
|
|
|
2328
|
|
|
|
|
|
|
'--print|:r' option specifies, that the output should be |
2329
|
|
|
|
|
|
|
printed on standard output. |
2330
|
|
|
|
|
|
|
|
2331
|
|
|
|
|
|
|
'--string|:s' option specifies, that the output should be |
2332
|
|
|
|
|
|
|
returned by the command as a string. In this case, the result |
2333
|
|
|
|
|
|
|
is always in UTF8, regardless on which encoding is specified |
2334
|
|
|
|
|
|
|
in the document or using '--encoding' option. |
2335
|
|
|
|
|
|
|
|
2336
|
|
|
|
|
|
|
The above four options are mutually exclusive. |
2337
|
|
|
|
|
|
|
|
2338
|
|
|
|
|
|
|
'--format' option may be used to specify the output format. |
2339
|
|
|
|
|
|
|
It's argument should be either 'xml', 'html' or an expression |
2340
|
|
|
|
|
|
|
evaluating to one of these. If not specified, XML output is |
2341
|
|
|
|
|
|
|
assumed. Note, that a document should be saved as HTML only if |
2342
|
|
|
|
|
|
|
it actually is a HTML document, otherwise the result would be |
2343
|
|
|
|
|
|
|
an invalid XML instance. Note also, that the optional encoding |
2344
|
|
|
|
|
|
|
parameter only forces character conversion; it is up to the |
2345
|
|
|
|
|
|
|
user to declare the document encoding in the appropriate HTML |
2346
|
|
|
|
|
|
|
tag, if needed. |
2347
|
|
|
|
|
|
|
|
2348
|
|
|
|
|
|
|
'--xinclude' automatically implies XML format and can be used |
2349
|
|
|
|
|
|
|
to force XSH2 to save all already expanded XInclude sections |
2350
|
|
|
|
|
|
|
back to their original files while replacing them with |
2351
|
|
|
|
|
|
|
tags in the main XML file. Moreover, all material |
2352
|
|
|
|
|
|
|
included within elements from the |
2353
|
|
|
|
|
|
|
http://www.w3.org/2001/XInclude namespace is saved to separate |
2354
|
|
|
|
|
|
|
files too according to the 'href' attribute, leaving only |
2355
|
|
|
|
|
|
|
empty element in the root file. This feature may be |
2356
|
|
|
|
|
|
|
used to split the document to a new set of XInclude fragments. |
2357
|
|
|
|
|
|
|
|
2358
|
|
|
|
|
|
|
If the '--subtree' (':S') flag is used, only the subtree of |
2359
|
|
|
|
|
|
|
the specified node is saved instead of the complete document |
2360
|
|
|
|
|
|
|
(this flag cannot be used with '--html' format). |
2361
|
|
|
|
|
|
|
|
2362
|
|
|
|
|
|
|
'--indent' (':i') and '--no-indent' (':I') may be used to |
2363
|
|
|
|
|
|
|
enforce/suppress indentation, overriding current global |
2364
|
|
|
|
|
|
|
setting of [indent]. |
2365
|
|
|
|
|
|
|
|
2366
|
|
|
|
|
|
|
'--skip-dtd' (':d') and '--no-skip-dtd' (':D') may be used to |
2367
|
|
|
|
|
|
|
enforce/suppress skipping DTD declaration and internal subset |
2368
|
|
|
|
|
|
|
on output, overriding current global setting of [skip-dtd]. |
2369
|
|
|
|
|
|
|
|
2370
|
|
|
|
|
|
|
'--empty-tags' (':t') and '--no-empty-tags' (':T') may be used |
2371
|
|
|
|
|
|
|
to override current global setting of [empty-tags]. |
2372
|
|
|
|
|
|
|
'--no-empty-tags' instructs XSH2 to serialize elements with no |
2373
|
|
|
|
|
|
|
child nodes as start-tag/end-tag pair '' |
2374
|
|
|
|
|
|
|
instead of using a short empty-tag form ''. |
2375
|
|
|
|
|
|
|
|
2376
|
|
|
|
|
|
|
'--skip-xmldecl' (':x') instructs XSH2 to omit the XML |
2377
|
|
|
|
|
|
|
declaration from the saved document. Note however, that XML |
2378
|
|
|
|
|
|
|
declaration is obligatory for XML documents. It usually looks |
2379
|
|
|
|
|
|
|
like ''. |
2380
|
|
|
|
|
|
|
|
2381
|
|
|
|
|
|
|
'--backup' (':b') and '--no-backup' (':B') can be used to |
2382
|
|
|
|
|
|
|
enforce/suppress creation of a backup file if target file |
2383
|
|
|
|
|
|
|
already exists. Using these options overrides current global |
2384
|
|
|
|
|
|
|
setting of [backups]. |
2385
|
|
|
|
|
|
|
|
2386
|
|
|
|
|
|
|
'--encoding' followed by a [encoding] instructs XSH2 to save |
2387
|
|
|
|
|
|
|
the document in the specified encoding. In case of XML output, |
2388
|
|
|
|
|
|
|
the declaration is automatically changed accordingly. |
2389
|
|
|
|
|
|
|
|
2390
|
|
|
|
|
|
|
Example: Use save to preview current HTML document in Lynx |
2391
|
|
|
|
|
|
|
|
2392
|
|
|
|
|
|
|
save --format html --pipe 'lynx -stdin' |
2393
|
|
|
|
|
|
|
|
2394
|
|
|
|
|
|
|
see also: open close enc documents |
2395
|
|
|
|
|
|
|
|
2396
|
|
|
|
|
|
|
END |
2397
|
|
|
|
|
|
|
|
2398
|
|
|
|
|
|
|
|
2399
|
|
|
|
|
|
|
$HELP{'set-dtd'}=[<<'END']; |
2400
|
|
|
|
|
|
|
usage: set-dtd [--internal] [--name|:n [expression]] |
2401
|
|
|
|
|
|
|
[--public|:p [expression]] |
2402
|
|
|
|
|
|
|
[--system|:s [expression]] |
2403
|
|
|
|
|
|
|
[[document]] |
2404
|
|
|
|
|
|
|
|
2405
|
|
|
|
|
|
|
aliases: set_dtd |
2406
|
|
|
|
|
|
|
|
2407
|
|
|
|
|
|
|
description: |
2408
|
|
|
|
|
|
|
Set external (default) or internal DTD for a given document. |
2409
|
|
|
|
|
|
|
If no [document] is given, the current document is used. At |
2410
|
|
|
|
|
|
|
least one of '--public' and '--system' options should be used |
2411
|
|
|
|
|
|
|
to specify the PUBLIC and SYSTEM identifiers of the DTD. If |
2412
|
|
|
|
|
|
|
'--name' parameter is not provided, name of the document root |
2413
|
|
|
|
|
|
|
element is used as DTD name. |
2414
|
|
|
|
|
|
|
|
2415
|
|
|
|
|
|
|
see also: dtd validate |
2416
|
|
|
|
|
|
|
|
2417
|
|
|
|
|
|
|
END |
2418
|
|
|
|
|
|
|
|
2419
|
|
|
|
|
|
|
$HELP{'set_dtd'}=$HELP{'set-dtd'}; |
2420
|
|
|
|
|
|
|
|
2421
|
|
|
|
|
|
|
$HELP{'dtd'}=[<<'END']; |
2422
|
|
|
|
|
|
|
usage: dtd [[document]] |
2423
|
|
|
|
|
|
|
|
2424
|
|
|
|
|
|
|
description: |
2425
|
|
|
|
|
|
|
Print external or internal DTD for a given document. If used |
2426
|
|
|
|
|
|
|
without arguments prints DTD of the current document. |
2427
|
|
|
|
|
|
|
|
2428
|
|
|
|
|
|
|
see also: set-dtd validate |
2429
|
|
|
|
|
|
|
|
2430
|
|
|
|
|
|
|
END |
2431
|
|
|
|
|
|
|
|
2432
|
|
|
|
|
|
|
|
2433
|
|
|
|
|
|
|
$HELP{'set-enc'}=[<<'END']; |
2434
|
|
|
|
|
|
|
usage: set-enc [encoding] [[document]] |
2435
|
|
|
|
|
|
|
|
2436
|
|
|
|
|
|
|
description: |
2437
|
|
|
|
|
|
|
Changes character encoding of a given document. If no |
2438
|
|
|
|
|
|
|
[document] is given, the command applies to the current |
2439
|
|
|
|
|
|
|
document. This has two effects: changing the XMLDecl encoding |
2440
|
|
|
|
|
|
|
declaration in the document prolog to display the new encoding |
2441
|
|
|
|
|
|
|
and making all future [save] operations on the document |
2442
|
|
|
|
|
|
|
default to the given charset. |
2443
|
|
|
|
|
|
|
|
2444
|
|
|
|
|
|
|
Example: |
2445
|
|
|
|
|
|
|
xsh> ls |
2446
|
|
|
|
|
|
|
|
2447
|
|
|
|
|
|
|
... |
2448
|
|
|
|
|
|
|
xsh> set-enc "utf-8" |
2449
|
|
|
|
|
|
|
xsh> ls |
2450
|
|
|
|
|
|
|
|
2451
|
|
|
|
|
|
|
... |
2452
|
|
|
|
|
|
|
xsh> save # saves the file in UTF-8 encoding |
2453
|
|
|
|
|
|
|
|
2454
|
|
|
|
|
|
|
see also: enc doc-info |
2455
|
|
|
|
|
|
|
|
2456
|
|
|
|
|
|
|
END |
2457
|
|
|
|
|
|
|
|
2458
|
|
|
|
|
|
|
|
2459
|
|
|
|
|
|
|
$HELP{'set-standalone'}=[<<'END']; |
2460
|
|
|
|
|
|
|
usage: set-standalone [expression] [[document]] |
2461
|
|
|
|
|
|
|
|
2462
|
|
|
|
|
|
|
description: |
2463
|
|
|
|
|
|
|
Changes the value of 'standalone' declaration in the XMLDecl |
2464
|
|
|
|
|
|
|
prolog of a document. The [expression] should evaluate to |
2465
|
|
|
|
|
|
|
either 1 or 0 or ''yes'' or ''no''. The result of applying the |
2466
|
|
|
|
|
|
|
command on other values is not specified. If no [document] is |
2467
|
|
|
|
|
|
|
given, the command applies to the current document. |
2468
|
|
|
|
|
|
|
|
2469
|
|
|
|
|
|
|
see also: doc-info |
2470
|
|
|
|
|
|
|
|
2471
|
|
|
|
|
|
|
END |
2472
|
|
|
|
|
|
|
|
2473
|
|
|
|
|
|
|
|
2474
|
|
|
|
|
|
|
$HELP{'enc'}=[<<'END']; |
2475
|
|
|
|
|
|
|
usage: enc [[document]] |
2476
|
|
|
|
|
|
|
|
2477
|
|
|
|
|
|
|
description: |
2478
|
|
|
|
|
|
|
Print the original document encoding string. If no [document] |
2479
|
|
|
|
|
|
|
is given, the current document is used. |
2480
|
|
|
|
|
|
|
|
2481
|
|
|
|
|
|
|
see also: set-enc |
2482
|
|
|
|
|
|
|
|
2483
|
|
|
|
|
|
|
END |
2484
|
|
|
|
|
|
|
|
2485
|
|
|
|
|
|
|
|
2486
|
|
|
|
|
|
|
$HELP{'validate'}=[<<'END']; |
2487
|
|
|
|
|
|
|
usage: validate [--yesno|:q] [[document]] |
2488
|
|
|
|
|
|
|
validate [--yesno|:q] [--dtd|:D | --relaxng|:R | --schema|:S] --file|:f [filename]] [[document]] |
2489
|
|
|
|
|
|
|
validate [--yesno|:q] [--dtd|:D | --relaxng|:R | --schema|:S] --string|:s [expression]] [[document]] |
2490
|
|
|
|
|
|
|
validate [--yesno|:q] [--dtd|:D | --relaxng|:R | --schema|:S] --doc|:d [document]] [[document]] |
2491
|
|
|
|
|
|
|
validate [--yesno|:q] [--dtd|:d] --public|:p [expression] [--file|:f [expression]] [[document]] |
2492
|
|
|
|
|
|
|
|
2493
|
|
|
|
|
|
|
description: |
2494
|
|
|
|
|
|
|
This command validates the current document or a document |
2495
|
|
|
|
|
|
|
specified in the argument against a DTD, RelaxNG or XSD |
2496
|
|
|
|
|
|
|
schema. If '--yesno' or ':q' is specified, only prints 'yes' |
2497
|
|
|
|
|
|
|
and returns 1 if the document validates or 'no' and returns 0 |
2498
|
|
|
|
|
|
|
if it does not. Without '--yesno', it throws an exception with |
2499
|
|
|
|
|
|
|
a complete validation error message if the document doesn't |
2500
|
|
|
|
|
|
|
validate. |
2501
|
|
|
|
|
|
|
|
2502
|
|
|
|
|
|
|
'--dtd' or ':D' forces DTD validation (default). |
2503
|
|
|
|
|
|
|
|
2504
|
|
|
|
|
|
|
'--relaxng' or ':R' forces RelaxNG validation. Only XML |
2505
|
|
|
|
|
|
|
RelaxNG grammars are supported. |
2506
|
|
|
|
|
|
|
|
2507
|
|
|
|
|
|
|
'--schema' or ':S' forces W3C XML Schema validation (XSD). |
2508
|
|
|
|
|
|
|
Support for schema validation may still be incomplete (see |
2509
|
|
|
|
|
|
|
libxml2 home page for more details). |
2510
|
|
|
|
|
|
|
|
2511
|
|
|
|
|
|
|
A DTD subset can be specified by its PUBLIC identifier (with |
2512
|
|
|
|
|
|
|
'--public'), by its SYSTEM identifier (with '--file'), or as a |
2513
|
|
|
|
|
|
|
string (with '--string'). If none of these options is used, |
2514
|
|
|
|
|
|
|
validation is performed against the internal or external DTD |
2515
|
|
|
|
|
|
|
subset of the document being validated. |
2516
|
|
|
|
|
|
|
|
2517
|
|
|
|
|
|
|
RelaxNG grammars and XML Schemas can either be specified |
2518
|
|
|
|
|
|
|
either as a filename or url (with '--file'), as a string |
2519
|
|
|
|
|
|
|
containing (with '--string'), or as a document currently open |
2520
|
|
|
|
|
|
|
in XSH2 (with '--doc'). |
2521
|
|
|
|
|
|
|
|
2522
|
|
|
|
|
|
|
Example: |
2523
|
|
|
|
|
|
|
$mydoc := open "test.xml" |
2524
|
|
|
|
|
|
|
# in all examples below, mydoc can be omitted |
2525
|
|
|
|
|
|
|
validate --yesno $mydoc; # validate against the document's DOCTYPE |
2526
|
|
|
|
|
|
|
validate --public "-//OASIS//DTD DocBook XML V4.1.2//EN" $mydoc |
2527
|
|
|
|
|
|
|
validate --file "http://www.oasis-open.org/docbook/xml/4.1.2/docbookx.dtd" $mydoc |
2528
|
|
|
|
|
|
|
|
2529
|
|
|
|
|
|
|
Example: |
2530
|
|
|
|
|
|
|
validate --relaxng --file "test.rng" $mydoc |
2531
|
|
|
|
|
|
|
validate --relaxng --string $relaxschema $mydoc |
2532
|
|
|
|
|
|
|
$rng := open "test.rng" |
2533
|
|
|
|
|
|
|
validate --relaxng --doc $rng $mydoc |
2534
|
|
|
|
|
|
|
|
2535
|
|
|
|
|
|
|
Example: |
2536
|
|
|
|
|
|
|
validate --schema --file "test.xsd" $mydoc |
2537
|
|
|
|
|
|
|
validate --schema --string $xsdschema $mydoc |
2538
|
|
|
|
|
|
|
$xsd := open "test.xsd" |
2539
|
|
|
|
|
|
|
validate --schema --doc $xsd $mydoc |
2540
|
|
|
|
|
|
|
|
2541
|
|
|
|
|
|
|
see also: dtd |
2542
|
|
|
|
|
|
|
|
2543
|
|
|
|
|
|
|
END |
2544
|
|
|
|
|
|
|
|
2545
|
|
|
|
|
|
|
|
2546
|
|
|
|
|
|
|
$HELP{'exit'}=[<<'END']; |
2547
|
|
|
|
|
|
|
usage: exit [[expression]] |
2548
|
|
|
|
|
|
|
|
2549
|
|
|
|
|
|
|
aliases: quit |
2550
|
|
|
|
|
|
|
|
2551
|
|
|
|
|
|
|
description: |
2552
|
|
|
|
|
|
|
Exit xsh, optionally with an exit-code resulting from |
2553
|
|
|
|
|
|
|
evaluation of a given [expression]. |
2554
|
|
|
|
|
|
|
|
2555
|
|
|
|
|
|
|
WARNING: No files are saved on exit. |
2556
|
|
|
|
|
|
|
|
2557
|
|
|
|
|
|
|
END |
2558
|
|
|
|
|
|
|
|
2559
|
|
|
|
|
|
|
$HELP{'quit'}=$HELP{'exit'}; |
2560
|
|
|
|
|
|
|
|
2561
|
|
|
|
|
|
|
$HELP{'process-xinclude'}=[<<'END']; |
2562
|
|
|
|
|
|
|
usage: process-xinclude [[document]] |
2563
|
|
|
|
|
|
|
|
2564
|
|
|
|
|
|
|
aliases: process_xinclude process-xincludes process_xincludes xinclude xincludes load_xincludes load-xincludes load_xinclude load-xinclude |
2565
|
|
|
|
|
|
|
|
2566
|
|
|
|
|
|
|
description: |
2567
|
|
|
|
|
|
|
Replace any xinclude tags in a given [document] with the |
2568
|
|
|
|
|
|
|
corresponding content. See http://www.w3.org/TR/xinclude/ to |
2569
|
|
|
|
|
|
|
find out more about XInclude technology. |
2570
|
|
|
|
|
|
|
|
2571
|
|
|
|
|
|
|
see also: parser-expands-xinclude |
2572
|
|
|
|
|
|
|
|
2573
|
|
|
|
|
|
|
END |
2574
|
|
|
|
|
|
|
|
2575
|
|
|
|
|
|
|
$HELP{'process_xinclude'}=$HELP{'process-xinclude'}; |
2576
|
|
|
|
|
|
|
$HELP{'process-xincludes'}=$HELP{'process-xinclude'}; |
2577
|
|
|
|
|
|
|
$HELP{'process_xincludes'}=$HELP{'process-xinclude'}; |
2578
|
|
|
|
|
|
|
$HELP{'xinclude'}=$HELP{'process-xinclude'}; |
2579
|
|
|
|
|
|
|
$HELP{'xincludes'}=$HELP{'process-xinclude'}; |
2580
|
|
|
|
|
|
|
$HELP{'load_xincludes'}=$HELP{'process-xinclude'}; |
2581
|
|
|
|
|
|
|
$HELP{'load-xincludes'}=$HELP{'process-xinclude'}; |
2582
|
|
|
|
|
|
|
$HELP{'load_xinclude'}=$HELP{'process-xinclude'}; |
2583
|
|
|
|
|
|
|
$HELP{'load-xinclude'}=$HELP{'process-xinclude'}; |
2584
|
|
|
|
|
|
|
|
2585
|
|
|
|
|
|
|
$HELP{'cd'}=[<<'END']; |
2586
|
|
|
|
|
|
|
usage: cd [[expression]] |
2587
|
|
|
|
|
|
|
|
2588
|
|
|
|
|
|
|
aliases: chxpath |
2589
|
|
|
|
|
|
|
|
2590
|
|
|
|
|
|
|
description: |
2591
|
|
|
|
|
|
|
Evaluate given [expression] to a node-list and change current |
2592
|
|
|
|
|
|
|
context node to the first node in it. |
2593
|
|
|
|
|
|
|
|
2594
|
|
|
|
|
|
|
END |
2595
|
|
|
|
|
|
|
|
2596
|
|
|
|
|
|
|
$HELP{'chxpath'}=$HELP{'cd'}; |
2597
|
|
|
|
|
|
|
|
2598
|
|
|
|
|
|
|
$HELP{'pwd'}=[<<'END']; |
2599
|
|
|
|
|
|
|
usage: pwd [--id|:i] |
2600
|
|
|
|
|
|
|
|
2601
|
|
|
|
|
|
|
description: |
2602
|
|
|
|
|
|
|
Print XPath leading to the current context node (equivalent to |
2603
|
|
|
|
|
|
|
'locate .'). |
2604
|
|
|
|
|
|
|
|
2605
|
|
|
|
|
|
|
If flag '--id' (':i') is used then ID-based shortcut is |
2606
|
|
|
|
|
|
|
allowed in the resulting location path. That means that if the |
2607
|
|
|
|
|
|
|
current node or some of its ancestors has an ID attribute |
2608
|
|
|
|
|
|
|
(either 'xml:id' or one specified in a DTD) then the |
2609
|
|
|
|
|
|
|
corresponding segment of the canonical location path is |
2610
|
|
|
|
|
|
|
replaced by the 'id()' function which jumps directly to an |
2611
|
|
|
|
|
|
|
element based on its ID. |
2612
|
|
|
|
|
|
|
|
2613
|
|
|
|
|
|
|
see also: locate xsh:path |
2614
|
|
|
|
|
|
|
|
2615
|
|
|
|
|
|
|
END |
2616
|
|
|
|
|
|
|
|
2617
|
|
|
|
|
|
|
|
2618
|
|
|
|
|
|
|
$HELP{'locate'}=[<<'END']; |
2619
|
|
|
|
|
|
|
usage: locate [--id|:i] [xpath] |
2620
|
|
|
|
|
|
|
|
2621
|
|
|
|
|
|
|
description: |
2622
|
|
|
|
|
|
|
Print canonical XPaths leading to nodes matched by a given |
2623
|
|
|
|
|
|
|
[xpath]. |
2624
|
|
|
|
|
|
|
|
2625
|
|
|
|
|
|
|
If flag '--id' (':i') is used then ID-based shortcuts are |
2626
|
|
|
|
|
|
|
allowed in the resulting location paths. That means that if |
2627
|
|
|
|
|
|
|
the node or some of its ancestors has an ID attribute (either |
2628
|
|
|
|
|
|
|
'xml:id' or one specified in a DTD) then the corresponding |
2629
|
|
|
|
|
|
|
segment of the canonical location path is replaced by the |
2630
|
|
|
|
|
|
|
'id()' function which jumps directly to an element based on |
2631
|
|
|
|
|
|
|
its ID. |
2632
|
|
|
|
|
|
|
|
2633
|
|
|
|
|
|
|
see also: pwd |
2634
|
|
|
|
|
|
|
|
2635
|
|
|
|
|
|
|
END |
2636
|
|
|
|
|
|
|
|
2637
|
|
|
|
|
|
|
|
2638
|
|
|
|
|
|
|
$HELP{'xupdate'}=[<<'END']; |
2639
|
|
|
|
|
|
|
usage: xupdate [document] [[document]] |
2640
|
|
|
|
|
|
|
|
2641
|
|
|
|
|
|
|
description: |
2642
|
|
|
|
|
|
|
Modify the current document or the document specified by the |
2643
|
|
|
|
|
|
|
second [document] argument according to XUpdate commands of |
2644
|
|
|
|
|
|
|
the first [document] argument. XUpdate, or more specifically |
2645
|
|
|
|
|
|
|
the XML Update Language, aims to be a language for updating |
2646
|
|
|
|
|
|
|
XML documents. |
2647
|
|
|
|
|
|
|
|
2648
|
|
|
|
|
|
|
XUpdate language is described in XUpdate Working Draft at |
2649
|
|
|
|
|
|
|
http://xmldb-org.sourceforge.net/xupdate/xupdate-wd.html. |
2650
|
|
|
|
|
|
|
|
2651
|
|
|
|
|
|
|
XUpdate output can be generated for example by Python xmldiff |
2652
|
|
|
|
|
|
|
utility from http://www.logilab.org/projects/xmldiff/. |
2653
|
|
|
|
|
|
|
|
2654
|
|
|
|
|
|
|
END |
2655
|
|
|
|
|
|
|
|
2656
|
|
|
|
|
|
|
|
2657
|
|
|
|
|
|
|
$HELP{'verbose'}=[<<'END']; |
2658
|
|
|
|
|
|
|
usage: verbose |
2659
|
|
|
|
|
|
|
|
2660
|
|
|
|
|
|
|
description: |
2661
|
|
|
|
|
|
|
Turn on verbose messages (default). |
2662
|
|
|
|
|
|
|
|
2663
|
|
|
|
|
|
|
This is equivalent to setting '$QUIET' variable to 0. |
2664
|
|
|
|
|
|
|
|
2665
|
|
|
|
|
|
|
see also: quiet |
2666
|
|
|
|
|
|
|
|
2667
|
|
|
|
|
|
|
END |
2668
|
|
|
|
|
|
|
|
2669
|
|
|
|
|
|
|
|
2670
|
|
|
|
|
|
|
$HELP{'test-mode'}=[<<'END']; |
2671
|
|
|
|
|
|
|
usage: test-mode |
2672
|
|
|
|
|
|
|
|
2673
|
|
|
|
|
|
|
aliases: test_mode |
2674
|
|
|
|
|
|
|
|
2675
|
|
|
|
|
|
|
description: |
2676
|
|
|
|
|
|
|
Switch into a mode in which no commands are actually executed |
2677
|
|
|
|
|
|
|
and only command syntax is checked. |
2678
|
|
|
|
|
|
|
|
2679
|
|
|
|
|
|
|
This is equivalent to setting '$TEST_MODE' variable to 1. |
2680
|
|
|
|
|
|
|
|
2681
|
|
|
|
|
|
|
see also: run-mode |
2682
|
|
|
|
|
|
|
|
2683
|
|
|
|
|
|
|
END |
2684
|
|
|
|
|
|
|
|
2685
|
|
|
|
|
|
|
$HELP{'test_mode'}=$HELP{'test-mode'}; |
2686
|
|
|
|
|
|
|
|
2687
|
|
|
|
|
|
|
$HELP{'run-mode'}=[<<'END']; |
2688
|
|
|
|
|
|
|
usage: run-mode |
2689
|
|
|
|
|
|
|
|
2690
|
|
|
|
|
|
|
aliases: run_mode |
2691
|
|
|
|
|
|
|
|
2692
|
|
|
|
|
|
|
description: |
2693
|
|
|
|
|
|
|
Switch from the [test-mode] back to the normal execution mode. |
2694
|
|
|
|
|
|
|
|
2695
|
|
|
|
|
|
|
This is equivalent to setting '$TEST_MODE' variable to 0. |
2696
|
|
|
|
|
|
|
|
2697
|
|
|
|
|
|
|
see also: test-mode |
2698
|
|
|
|
|
|
|
|
2699
|
|
|
|
|
|
|
END |
2700
|
|
|
|
|
|
|
|
2701
|
|
|
|
|
|
|
$HELP{'run_mode'}=$HELP{'run-mode'}; |
2702
|
|
|
|
|
|
|
|
2703
|
|
|
|
|
|
|
$HELP{'debug'}=[<<'END']; |
2704
|
|
|
|
|
|
|
usage: debug |
2705
|
|
|
|
|
|
|
|
2706
|
|
|
|
|
|
|
description: |
2707
|
|
|
|
|
|
|
Turn on debugging messages. |
2708
|
|
|
|
|
|
|
|
2709
|
|
|
|
|
|
|
This is equivalent to setting '$DEBUG' variable to 1. |
2710
|
|
|
|
|
|
|
|
2711
|
|
|
|
|
|
|
see also: nodebug |
2712
|
|
|
|
|
|
|
|
2713
|
|
|
|
|
|
|
END |
2714
|
|
|
|
|
|
|
|
2715
|
|
|
|
|
|
|
|
2716
|
|
|
|
|
|
|
$HELP{'nodebug'}=[<<'END']; |
2717
|
|
|
|
|
|
|
usage: nodebug |
2718
|
|
|
|
|
|
|
|
2719
|
|
|
|
|
|
|
description: |
2720
|
|
|
|
|
|
|
Turn off debugging messages. |
2721
|
|
|
|
|
|
|
|
2722
|
|
|
|
|
|
|
This is equivalent to setting '$DEBUG' variable to 0. |
2723
|
|
|
|
|
|
|
|
2724
|
|
|
|
|
|
|
see also: debug |
2725
|
|
|
|
|
|
|
|
2726
|
|
|
|
|
|
|
END |
2727
|
|
|
|
|
|
|
|
2728
|
|
|
|
|
|
|
|
2729
|
|
|
|
|
|
|
$HELP{'version'}=[<<'END']; |
2730
|
|
|
|
|
|
|
usage: version |
2731
|
|
|
|
|
|
|
|
2732
|
|
|
|
|
|
|
description: |
2733
|
|
|
|
|
|
|
Prints program version plus version numbers of the most |
2734
|
|
|
|
|
|
|
important libraries used. |
2735
|
|
|
|
|
|
|
|
2736
|
|
|
|
|
|
|
END |
2737
|
|
|
|
|
|
|
|
2738
|
|
|
|
|
|
|
|
2739
|
|
|
|
|
|
|
$HELP{'validation'}=[<<'END']; |
2740
|
|
|
|
|
|
|
usage: validation [expression] |
2741
|
|
|
|
|
|
|
|
2742
|
|
|
|
|
|
|
description: |
2743
|
|
|
|
|
|
|
Turn on validation during the parse process if the |
2744
|
|
|
|
|
|
|
[expression] is non-zero or off otherwise. Defaults to off. |
2745
|
|
|
|
|
|
|
|
2746
|
|
|
|
|
|
|
This command is equivalent to setting the '$VALIDATION' |
2747
|
|
|
|
|
|
|
variable. |
2748
|
|
|
|
|
|
|
|
2749
|
|
|
|
|
|
|
END |
2750
|
|
|
|
|
|
|
|
2751
|
|
|
|
|
|
|
|
2752
|
|
|
|
|
|
|
$HELP{'recovering'}=[<<'END']; |
2753
|
|
|
|
|
|
|
usage: recovering [expression] |
2754
|
|
|
|
|
|
|
|
2755
|
|
|
|
|
|
|
description: |
2756
|
|
|
|
|
|
|
If the [expression] evaluates to non-zero value, turn on the |
2757
|
|
|
|
|
|
|
recovering parser mode on; turn it off otherwise. Defaults to |
2758
|
|
|
|
|
|
|
off. |
2759
|
|
|
|
|
|
|
|
2760
|
|
|
|
|
|
|
Note, that the in the recovering mode, validation is not |
2761
|
|
|
|
|
|
|
performed by the parser even if the validation flag is on. |
2762
|
|
|
|
|
|
|
|
2763
|
|
|
|
|
|
|
The recover mode helps to efficiently recover documents that |
2764
|
|
|
|
|
|
|
are almost well-formed. This for example includes documents |
2765
|
|
|
|
|
|
|
without a close tag for the document element (or any other |
2766
|
|
|
|
|
|
|
element inside the document). |
2767
|
|
|
|
|
|
|
|
2768
|
|
|
|
|
|
|
This command is equivalent to setting the '$RECOVERING' |
2769
|
|
|
|
|
|
|
variable. |
2770
|
|
|
|
|
|
|
|
2771
|
|
|
|
|
|
|
END |
2772
|
|
|
|
|
|
|
|
2773
|
|
|
|
|
|
|
|
2774
|
|
|
|
|
|
|
$HELP{'parser-expands-entities'}=[<<'END']; |
2775
|
|
|
|
|
|
|
usage: parser-expands-entities [expression] |
2776
|
|
|
|
|
|
|
|
2777
|
|
|
|
|
|
|
aliases: parser_expands_entities |
2778
|
|
|
|
|
|
|
|
2779
|
|
|
|
|
|
|
description: |
2780
|
|
|
|
|
|
|
If the [expression] is non-zero enable the entity expansion |
2781
|
|
|
|
|
|
|
during the parse process; disable it otherwise. If entity |
2782
|
|
|
|
|
|
|
expansion is disabled, any external entity references in |
2783
|
|
|
|
|
|
|
parsed documents are preserved as references. By default, |
2784
|
|
|
|
|
|
|
entity expansion is enabled. |
2785
|
|
|
|
|
|
|
|
2786
|
|
|
|
|
|
|
This command is equivalent to setting the |
2787
|
|
|
|
|
|
|
'$PARSER_EXPANDS_ENTITIES' variable. |
2788
|
|
|
|
|
|
|
|
2789
|
|
|
|
|
|
|
END |
2790
|
|
|
|
|
|
|
|
2791
|
|
|
|
|
|
|
$HELP{'parser_expands_entities'}=$HELP{'parser-expands-entities'}; |
2792
|
|
|
|
|
|
|
|
2793
|
|
|
|
|
|
|
$HELP{'keep-blanks'}=[<<'END']; |
2794
|
|
|
|
|
|
|
usage: keep-blanks [expression] |
2795
|
|
|
|
|
|
|
|
2796
|
|
|
|
|
|
|
aliases: keep_blanks |
2797
|
|
|
|
|
|
|
|
2798
|
|
|
|
|
|
|
description: |
2799
|
|
|
|
|
|
|
Allows you to turn on/off preserving the parser's default |
2800
|
|
|
|
|
|
|
behavior of preserving all whitespace in the document. Setting |
2801
|
|
|
|
|
|
|
this option to 0, instructs the XML parser to ignore |
2802
|
|
|
|
|
|
|
whitespace occurring between adjacent element nodes, so that |
2803
|
|
|
|
|
|
|
no extra text nodes are created for it. |
2804
|
|
|
|
|
|
|
|
2805
|
|
|
|
|
|
|
This command is equivalent to setting the '$KEEP_BLANKS' |
2806
|
|
|
|
|
|
|
variable. |
2807
|
|
|
|
|
|
|
|
2808
|
|
|
|
|
|
|
END |
2809
|
|
|
|
|
|
|
|
2810
|
|
|
|
|
|
|
$HELP{'keep_blanks'}=$HELP{'keep-blanks'}; |
2811
|
|
|
|
|
|
|
|
2812
|
|
|
|
|
|
|
$HELP{'pedantic-parser'}=[<<'END']; |
2813
|
|
|
|
|
|
|
usage: pedantic-parser [expression] |
2814
|
|
|
|
|
|
|
|
2815
|
|
|
|
|
|
|
aliases: pedantic_parser |
2816
|
|
|
|
|
|
|
|
2817
|
|
|
|
|
|
|
description: |
2818
|
|
|
|
|
|
|
If you wish, you can make the XML parser little more pedantic |
2819
|
|
|
|
|
|
|
by passing a non-zero [expression] to this command. |
2820
|
|
|
|
|
|
|
|
2821
|
|
|
|
|
|
|
This command is equivalent to setting the '$PEDANTIC_PARSER' |
2822
|
|
|
|
|
|
|
variable. |
2823
|
|
|
|
|
|
|
|
2824
|
|
|
|
|
|
|
END |
2825
|
|
|
|
|
|
|
|
2826
|
|
|
|
|
|
|
$HELP{'pedantic_parser'}=$HELP{'pedantic-parser'}; |
2827
|
|
|
|
|
|
|
|
2828
|
|
|
|
|
|
|
$HELP{'parser-completes-attributes'}=[<<'END']; |
2829
|
|
|
|
|
|
|
usage: parser-completes-attributes [expression] |
2830
|
|
|
|
|
|
|
|
2831
|
|
|
|
|
|
|
aliases: complete_attributes complete-attributes parser_completes_attributes |
2832
|
|
|
|
|
|
|
|
2833
|
|
|
|
|
|
|
description: |
2834
|
|
|
|
|
|
|
If the expression is non-zero, the command makes XML parser |
2835
|
|
|
|
|
|
|
add missing attributes with default values as specified in a |
2836
|
|
|
|
|
|
|
DTD. By default, this option is enabled. |
2837
|
|
|
|
|
|
|
|
2838
|
|
|
|
|
|
|
This command is equivalent to setting the |
2839
|
|
|
|
|
|
|
'$PARSER_COMPLETES_ATTRIBUTES' variable. |
2840
|
|
|
|
|
|
|
|
2841
|
|
|
|
|
|
|
END |
2842
|
|
|
|
|
|
|
|
2843
|
|
|
|
|
|
|
$HELP{'complete_attributes'}=$HELP{'parser-completes-attributes'}; |
2844
|
|
|
|
|
|
|
$HELP{'complete-attributes'}=$HELP{'parser-completes-attributes'}; |
2845
|
|
|
|
|
|
|
$HELP{'parser_completes_attributes'}=$HELP{'parser-completes-attributes'}; |
2846
|
|
|
|
|
|
|
|
2847
|
|
|
|
|
|
|
$HELP{'indent'}=[<<'END']; |
2848
|
|
|
|
|
|
|
usage: indent [expression] |
2849
|
|
|
|
|
|
|
|
2850
|
|
|
|
|
|
|
description: |
2851
|
|
|
|
|
|
|
If the value of [expression] is 1, saved and listed XML will |
2852
|
|
|
|
|
|
|
be formatted using some (hopefully) ignorable whitespace. If |
2853
|
|
|
|
|
|
|
the value is 2 (or higher), XSH2 will act as in case of 1, |
2854
|
|
|
|
|
|
|
plus it will add a leading and a trailing linebreak to each |
2855
|
|
|
|
|
|
|
text node. |
2856
|
|
|
|
|
|
|
|
2857
|
|
|
|
|
|
|
Note, that since the underlying C library (libxml2) uses a |
2858
|
|
|
|
|
|
|
hard-coded indentation of 2 space characters per indentation |
2859
|
|
|
|
|
|
|
level, the amount of whitespace used for indentation can not |
2860
|
|
|
|
|
|
|
be altered at runtime. |
2861
|
|
|
|
|
|
|
|
2862
|
|
|
|
|
|
|
This command is equivalent to setting the '$INDENT' variable. |
2863
|
|
|
|
|
|
|
|
2864
|
|
|
|
|
|
|
END |
2865
|
|
|
|
|
|
|
|
2866
|
|
|
|
|
|
|
|
2867
|
|
|
|
|
|
|
$HELP{'empty-tags'}=[<<'END']; |
2868
|
|
|
|
|
|
|
usage: empty-tags [expression] |
2869
|
|
|
|
|
|
|
|
2870
|
|
|
|
|
|
|
aliases: empty_tags |
2871
|
|
|
|
|
|
|
|
2872
|
|
|
|
|
|
|
description: |
2873
|
|
|
|
|
|
|
If the value of [expression] is 1 (non-zero), empty tags are |
2874
|
|
|
|
|
|
|
serialized as a start-tag/end-tag pair (''). This |
2875
|
|
|
|
|
|
|
option affects both [ls] and [save] and possibly other |
2876
|
|
|
|
|
|
|
commands. Otherwise, they are compacted into a short-tag form |
2877
|
|
|
|
|
|
|
(''). Default value is '0'. |
2878
|
|
|
|
|
|
|
|
2879
|
|
|
|
|
|
|
This command is equivalent to setting the '$EMPTY_TAGS' |
2880
|
|
|
|
|
|
|
variable. |
2881
|
|
|
|
|
|
|
|
2882
|
|
|
|
|
|
|
END |
2883
|
|
|
|
|
|
|
|
2884
|
|
|
|
|
|
|
$HELP{'empty_tags'}=$HELP{'empty-tags'}; |
2885
|
|
|
|
|
|
|
|
2886
|
|
|
|
|
|
|
$HELP{'skip-dtd'}=[<<'END']; |
2887
|
|
|
|
|
|
|
usage: skip-dtd [expression] |
2888
|
|
|
|
|
|
|
|
2889
|
|
|
|
|
|
|
aliases: skip_dtd |
2890
|
|
|
|
|
|
|
|
2891
|
|
|
|
|
|
|
description: |
2892
|
|
|
|
|
|
|
If the value of [expression] is 1 (non-zero), DTD DOCTYPE |
2893
|
|
|
|
|
|
|
declaration is omitted from any further serializations of XML |
2894
|
|
|
|
|
|
|
documents (including [ls] and [save]). Default value is '0'. |
2895
|
|
|
|
|
|
|
|
2896
|
|
|
|
|
|
|
This command is equivalent to setting the '$SKIP_DTD' |
2897
|
|
|
|
|
|
|
variable. |
2898
|
|
|
|
|
|
|
|
2899
|
|
|
|
|
|
|
END |
2900
|
|
|
|
|
|
|
|
2901
|
|
|
|
|
|
|
$HELP{'skip_dtd'}=$HELP{'skip-dtd'}; |
2902
|
|
|
|
|
|
|
|
2903
|
|
|
|
|
|
|
$HELP{'parser-expands-xinclude'}=[<<'END']; |
2904
|
|
|
|
|
|
|
usage: parser-expands-xinclude [expression] |
2905
|
|
|
|
|
|
|
|
2906
|
|
|
|
|
|
|
aliases: parser_expands_xinclude |
2907
|
|
|
|
|
|
|
|
2908
|
|
|
|
|
|
|
description: |
2909
|
|
|
|
|
|
|
If the [expression] is non-zero, the parser is allowed to |
2910
|
|
|
|
|
|
|
expand XInclude tags immediately while parsing the document. |
2911
|
|
|
|
|
|
|
|
2912
|
|
|
|
|
|
|
This command is equivalent to setting the |
2913
|
|
|
|
|
|
|
'$PARSER_EXPANDS_XINCLUDE' variable. |
2914
|
|
|
|
|
|
|
|
2915
|
|
|
|
|
|
|
see also: process-xinclude |
2916
|
|
|
|
|
|
|
|
2917
|
|
|
|
|
|
|
END |
2918
|
|
|
|
|
|
|
|
2919
|
|
|
|
|
|
|
$HELP{'parser_expands_xinclude'}=$HELP{'parser-expands-xinclude'}; |
2920
|
|
|
|
|
|
|
|
2921
|
|
|
|
|
|
|
$HELP{'load-ext-dtd'}=[<<'END']; |
2922
|
|
|
|
|
|
|
usage: load-ext-dtd [expression] |
2923
|
|
|
|
|
|
|
|
2924
|
|
|
|
|
|
|
aliases: load_ext_dtd |
2925
|
|
|
|
|
|
|
|
2926
|
|
|
|
|
|
|
description: |
2927
|
|
|
|
|
|
|
Non-zero [expression] instructs the XML parser to load |
2928
|
|
|
|
|
|
|
external DTD subsets declared in XML documents. This option is |
2929
|
|
|
|
|
|
|
enabled by default. |
2930
|
|
|
|
|
|
|
|
2931
|
|
|
|
|
|
|
This command is equivalent to setting the '$LOAD_EXT_DTD' |
2932
|
|
|
|
|
|
|
variable. |
2933
|
|
|
|
|
|
|
|
2934
|
|
|
|
|
|
|
END |
2935
|
|
|
|
|
|
|
|
2936
|
|
|
|
|
|
|
$HELP{'load_ext_dtd'}=$HELP{'load-ext-dtd'}; |
2937
|
|
|
|
|
|
|
|
2938
|
|
|
|
|
|
|
$HELP{'encoding'}=[<<'END']; |
2939
|
|
|
|
|
|
|
usage: encoding [encoding] |
2940
|
|
|
|
|
|
|
|
2941
|
|
|
|
|
|
|
description: |
2942
|
|
|
|
|
|
|
Set the default character encoding used for standard (e.g. |
2943
|
|
|
|
|
|
|
terminal) output. This doesn't influence the encoding used for |
2944
|
|
|
|
|
|
|
saving XML documents. |
2945
|
|
|
|
|
|
|
|
2946
|
|
|
|
|
|
|
This command is equivalent to setting the '$ENCODING' |
2947
|
|
|
|
|
|
|
variable. |
2948
|
|
|
|
|
|
|
|
2949
|
|
|
|
|
|
|
see also: query-encoding |
2950
|
|
|
|
|
|
|
|
2951
|
|
|
|
|
|
|
END |
2952
|
|
|
|
|
|
|
|
2953
|
|
|
|
|
|
|
|
2954
|
|
|
|
|
|
|
$HELP{'query-encoding'}=[<<'END']; |
2955
|
|
|
|
|
|
|
usage: query-encoding [encoding] |
2956
|
|
|
|
|
|
|
|
2957
|
|
|
|
|
|
|
aliases: query_encoding |
2958
|
|
|
|
|
|
|
|
2959
|
|
|
|
|
|
|
description: |
2960
|
|
|
|
|
|
|
Set the default query character encoding, i.e. encoding used |
2961
|
|
|
|
|
|
|
when taking input from XSH2 prompt or standard input. |
2962
|
|
|
|
|
|
|
|
2963
|
|
|
|
|
|
|
This command is equivalent to setting the '$QUERY_ENCODING' |
2964
|
|
|
|
|
|
|
variable. |
2965
|
|
|
|
|
|
|
|
2966
|
|
|
|
|
|
|
see also: encoding |
2967
|
|
|
|
|
|
|
|
2968
|
|
|
|
|
|
|
END |
2969
|
|
|
|
|
|
|
|
2970
|
|
|
|
|
|
|
$HELP{'query_encoding'}=$HELP{'query-encoding'}; |
2971
|
|
|
|
|
|
|
|
2972
|
|
|
|
|
|
|
$HELP{'quiet'}=[<<'END']; |
2973
|
|
|
|
|
|
|
usage: quiet |
2974
|
|
|
|
|
|
|
|
2975
|
|
|
|
|
|
|
description: |
2976
|
|
|
|
|
|
|
Turn off verbose messages. |
2977
|
|
|
|
|
|
|
|
2978
|
|
|
|
|
|
|
This command is equivalent to setting the '$QUIET' variable. |
2979
|
|
|
|
|
|
|
|
2980
|
|
|
|
|
|
|
see also: verbose |
2981
|
|
|
|
|
|
|
|
2982
|
|
|
|
|
|
|
END |
2983
|
|
|
|
|
|
|
|
2984
|
|
|
|
|
|
|
|
2985
|
|
|
|
|
|
|
$HELP{'switch-to-new-documents'}=[<<'END']; |
2986
|
|
|
|
|
|
|
usage: switch-to-new-documents [expression] |
2987
|
|
|
|
|
|
|
|
2988
|
|
|
|
|
|
|
aliases: switch_to_new_documents |
2989
|
|
|
|
|
|
|
|
2990
|
|
|
|
|
|
|
description: |
2991
|
|
|
|
|
|
|
If non-zero, XSH2 changes current node to the document node of |
2992
|
|
|
|
|
|
|
a newly open/created files every time a new document is opened |
2993
|
|
|
|
|
|
|
or created with [open] or [create]. Default value for this |
2994
|
|
|
|
|
|
|
option is 1. |
2995
|
|
|
|
|
|
|
|
2996
|
|
|
|
|
|
|
This command is equivalent to setting the |
2997
|
|
|
|
|
|
|
'$SWITCH_TO_NEW_DOCUMENTS' variable. |
2998
|
|
|
|
|
|
|
|
2999
|
|
|
|
|
|
|
END |
3000
|
|
|
|
|
|
|
|
3001
|
|
|
|
|
|
|
$HELP{'switch_to_new_documents'}=$HELP{'switch-to-new-documents'}; |
3002
|
|
|
|
|
|
|
|
3003
|
|
|
|
|
|
|
$HELP{'backups'}=[<<'END']; |
3004
|
|
|
|
|
|
|
usage: backups |
3005
|
|
|
|
|
|
|
|
3006
|
|
|
|
|
|
|
description: |
3007
|
|
|
|
|
|
|
Enable creating backup files on save (default). |
3008
|
|
|
|
|
|
|
|
3009
|
|
|
|
|
|
|
This command is equivalent to setting the '$BACKUPS' variable |
3010
|
|
|
|
|
|
|
to 1. |
3011
|
|
|
|
|
|
|
|
3012
|
|
|
|
|
|
|
see also: nobackups |
3013
|
|
|
|
|
|
|
|
3014
|
|
|
|
|
|
|
END |
3015
|
|
|
|
|
|
|
|
3016
|
|
|
|
|
|
|
|
3017
|
|
|
|
|
|
|
$HELP{'nobackups'}=[<<'END']; |
3018
|
|
|
|
|
|
|
usage: nobackups |
3019
|
|
|
|
|
|
|
|
3020
|
|
|
|
|
|
|
description: |
3021
|
|
|
|
|
|
|
Disable creating backup files on save. |
3022
|
|
|
|
|
|
|
|
3023
|
|
|
|
|
|
|
This command is equivalent to setting the '$BACKUPS' variable |
3024
|
|
|
|
|
|
|
to 0. |
3025
|
|
|
|
|
|
|
|
3026
|
|
|
|
|
|
|
see also: nobackups |
3027
|
|
|
|
|
|
|
|
3028
|
|
|
|
|
|
|
END |
3029
|
|
|
|
|
|
|
|
3030
|
|
|
|
|
|
|
|
3031
|
|
|
|
|
|
|
$HELP{'fold'}=[<<'END']; |
3032
|
|
|
|
|
|
|
usage: fold [--depth|:d [expression]] [[expression]] |
3033
|
|
|
|
|
|
|
|
3034
|
|
|
|
|
|
|
description: |
3035
|
|
|
|
|
|
|
This feature is still EXPERIMENTAL and may change in the |
3036
|
|
|
|
|
|
|
future! Fold command may be used to mark elements with a |
3037
|
|
|
|
|
|
|
'xsh:fold' attribute from the |
3038
|
|
|
|
|
|
|
'http://xsh.sourceforge.net/xsh/' namespace. When listing the |
3039
|
|
|
|
|
|
|
DOM tree using '[ls] --fold [xpath]', elements marked in this |
3040
|
|
|
|
|
|
|
way are folded to a given depth (default is 0 = fold |
3041
|
|
|
|
|
|
|
immediately). |
3042
|
|
|
|
|
|
|
|
3043
|
|
|
|
|
|
|
The option '--depth' (':d') may be used to specify the depth |
3044
|
|
|
|
|
|
|
at which subtrees of given elements are to be folded. |
3045
|
|
|
|
|
|
|
|
3046
|
|
|
|
|
|
|
If called without arguments, the command applies to the |
3047
|
|
|
|
|
|
|
current element, otherwise the [expression] is evaluated to |
3048
|
|
|
|
|
|
|
the node-list and folding is applied to all elements within |
3049
|
|
|
|
|
|
|
this node-list. |
3050
|
|
|
|
|
|
|
|
3051
|
|
|
|
|
|
|
Example: |
3052
|
|
|
|
|
|
|
xsh> fold --depth 1 //chapter |
3053
|
|
|
|
|
|
|
xsh> ls --fold //chapter[1] |
3054
|
|
|
|
|
|
|
|
3055
|
|
|
|
|
|
|
... |
3056
|
|
|
|
|
|
|
... |
3057
|
|
|
|
|
|
|
... |
3058
|
|
|
|
|
|
|
|
3059
|
|
|
|
|
|
|
|
3060
|
|
|
|
|
|
|
see also: unfold ls |
3061
|
|
|
|
|
|
|
|
3062
|
|
|
|
|
|
|
END |
3063
|
|
|
|
|
|
|
|
3064
|
|
|
|
|
|
|
|
3065
|
|
|
|
|
|
|
$HELP{'unfold'}=[<<'END']; |
3066
|
|
|
|
|
|
|
usage: unfold [expression] |
3067
|
|
|
|
|
|
|
|
3068
|
|
|
|
|
|
|
description: |
3069
|
|
|
|
|
|
|
This feature is still EXPERIMENTAL! |
3070
|
|
|
|
|
|
|
|
3071
|
|
|
|
|
|
|
Unfold command removes 'xsh:fold' attributes from all given |
3072
|
|
|
|
|
|
|
elements. Such attributes are usually created by previous |
3073
|
|
|
|
|
|
|
usage of [fold]. Be aware, that 'xmlns:xsh' namespace |
3074
|
|
|
|
|
|
|
declaration may still be present in the document even when all |
3075
|
|
|
|
|
|
|
elements are unfolded. |
3076
|
|
|
|
|
|
|
|
3077
|
|
|
|
|
|
|
see also: fold ls |
3078
|
|
|
|
|
|
|
|
3079
|
|
|
|
|
|
|
END |
3080
|
|
|
|
|
|
|
|
3081
|
|
|
|
|
|
|
|
3082
|
|
|
|
|
|
|
$HELP{'redo'}=[<<'END']; |
3083
|
|
|
|
|
|
|
usage: redo [[expression]] |
3084
|
|
|
|
|
|
|
|
3085
|
|
|
|
|
|
|
description: |
3086
|
|
|
|
|
|
|
'redo' restarts a loop block without evaluating the |
3087
|
|
|
|
|
|
|
conditional again. The optional [expression] argument may |
3088
|
|
|
|
|
|
|
evaluate to a positive integer number that indicates which |
3089
|
|
|
|
|
|
|
level of the nested loops should be restarted. If omitted, it |
3090
|
|
|
|
|
|
|
defaults to 1, i.e. the innermost loop. |
3091
|
|
|
|
|
|
|
|
3092
|
|
|
|
|
|
|
Using this command outside a loop causes an immediate run-time |
3093
|
|
|
|
|
|
|
error. |
3094
|
|
|
|
|
|
|
|
3095
|
|
|
|
|
|
|
Example: Restart a higher level loop from an inner one |
3096
|
|
|
|
|
|
|
|
3097
|
|
|
|
|
|
|
while ($i<100) { |
3098
|
|
|
|
|
|
|
# ... |
3099
|
|
|
|
|
|
|
foreach //para { |
3100
|
|
|
|
|
|
|
# some code |
3101
|
|
|
|
|
|
|
if $param { |
3102
|
|
|
|
|
|
|
redo; # redo foreach loop |
3103
|
|
|
|
|
|
|
} else { |
3104
|
|
|
|
|
|
|
redo 2; # redo while loop |
3105
|
|
|
|
|
|
|
} |
3106
|
|
|
|
|
|
|
} |
3107
|
|
|
|
|
|
|
} |
3108
|
|
|
|
|
|
|
|
3109
|
|
|
|
|
|
|
see also: foreach while iterate next last |
3110
|
|
|
|
|
|
|
|
3111
|
|
|
|
|
|
|
END |
3112
|
|
|
|
|
|
|
|
3113
|
|
|
|
|
|
|
|
3114
|
|
|
|
|
|
|
$HELP{'next'}=[<<'END']; |
3115
|
|
|
|
|
|
|
usage: next [[expression]] |
3116
|
|
|
|
|
|
|
|
3117
|
|
|
|
|
|
|
description: |
3118
|
|
|
|
|
|
|
'next' is like the continue statement in C; it starts the next |
3119
|
|
|
|
|
|
|
iteration of an enclosing loop. The command may be used with |
3120
|
|
|
|
|
|
|
an optional argument evaluating to a positive integer number |
3121
|
|
|
|
|
|
|
indicating which level of the nested loops should be |
3122
|
|
|
|
|
|
|
restarted. If the argument is omitted, it defaults to 1, i.e. |
3123
|
|
|
|
|
|
|
the innermost loop. |
3124
|
|
|
|
|
|
|
|
3125
|
|
|
|
|
|
|
Using this command outside a loop causes an immediate run-time |
3126
|
|
|
|
|
|
|
error. |
3127
|
|
|
|
|
|
|
|
3128
|
|
|
|
|
|
|
see also: foreach while iterate redo last prev |
3129
|
|
|
|
|
|
|
|
3130
|
|
|
|
|
|
|
END |
3131
|
|
|
|
|
|
|
|
3132
|
|
|
|
|
|
|
|
3133
|
|
|
|
|
|
|
$HELP{'prev'}=[<<'END']; |
3134
|
|
|
|
|
|
|
usage: prev [[expression]] |
3135
|
|
|
|
|
|
|
|
3136
|
|
|
|
|
|
|
description: |
3137
|
|
|
|
|
|
|
This command is only allowed inside an 'iterate' loop. It |
3138
|
|
|
|
|
|
|
returns the iteration one step back, to the previous node on |
3139
|
|
|
|
|
|
|
the iterated axis. The optional [expression] argument may be |
3140
|
|
|
|
|
|
|
used to indicate to which level of nested loops the command |
3141
|
|
|
|
|
|
|
applies to (default is 1). |
3142
|
|
|
|
|
|
|
|
3143
|
|
|
|
|
|
|
see also: iterate redo last next |
3144
|
|
|
|
|
|
|
|
3145
|
|
|
|
|
|
|
END |
3146
|
|
|
|
|
|
|
|
3147
|
|
|
|
|
|
|
|
3148
|
|
|
|
|
|
|
$HELP{'last'}=[<<'END']; |
3149
|
|
|
|
|
|
|
usage: last [[expression]] |
3150
|
|
|
|
|
|
|
|
3151
|
|
|
|
|
|
|
description: |
3152
|
|
|
|
|
|
|
The 'last' command is like the break statement in C (as used |
3153
|
|
|
|
|
|
|
in loops); it immediately exits an enclosing loop. The |
3154
|
|
|
|
|
|
|
optional [expression] argument may evaluate to a positive |
3155
|
|
|
|
|
|
|
integer number that indicates which level of the nested loops |
3156
|
|
|
|
|
|
|
to quit. If this argument is omitted, it defaults to 1, i.e. |
3157
|
|
|
|
|
|
|
the innermost loop. |
3158
|
|
|
|
|
|
|
|
3159
|
|
|
|
|
|
|
Using this command outside a loop causes an immediate run-time |
3160
|
|
|
|
|
|
|
error. |
3161
|
|
|
|
|
|
|
|
3162
|
|
|
|
|
|
|
see also: foreach while iterate next last |
3163
|
|
|
|
|
|
|
|
3164
|
|
|
|
|
|
|
END |
3165
|
|
|
|
|
|
|
|
3166
|
|
|
|
|
|
|
|
3167
|
|
|
|
|
|
|
$HELP{'return'}=[<<'END']; |
3168
|
|
|
|
|
|
|
usage: return [[expression]] |
3169
|
|
|
|
|
|
|
|
3170
|
|
|
|
|
|
|
description: |
3171
|
|
|
|
|
|
|
This command immediately stops the execution of a procedure it |
3172
|
|
|
|
|
|
|
occurs in and returns the execution to the place of the script |
3173
|
|
|
|
|
|
|
from which the subroutine was called. Optional argument may be |
3174
|
|
|
|
|
|
|
used as a return value for the subroutine call. |
3175
|
|
|
|
|
|
|
|
3176
|
|
|
|
|
|
|
Using this command outside a subroutine causes an immediate |
3177
|
|
|
|
|
|
|
run-time error. |
3178
|
|
|
|
|
|
|
|
3179
|
|
|
|
|
|
|
see also: def call |
3180
|
|
|
|
|
|
|
|
3181
|
|
|
|
|
|
|
END |
3182
|
|
|
|
|
|
|
|
3183
|
|
|
|
|
|
|
|
3184
|
|
|
|
|
|
|
$HELP{'throw'}=[<<'END']; |
3185
|
|
|
|
|
|
|
usage: throw [expression] |
3186
|
|
|
|
|
|
|
|
3187
|
|
|
|
|
|
|
description: |
3188
|
|
|
|
|
|
|
This command throws and exception containing error message |
3189
|
|
|
|
|
|
|
given by the obligatory [expression] argument. If the |
3190
|
|
|
|
|
|
|
exception is not handled by some surrounding [try] block, the |
3191
|
|
|
|
|
|
|
execution is stopped immediately and the error message is |
3192
|
|
|
|
|
|
|
printed. |
3193
|
|
|
|
|
|
|
|
3194
|
|
|
|
|
|
|
see also: try |
3195
|
|
|
|
|
|
|
|
3196
|
|
|
|
|
|
|
END |
3197
|
|
|
|
|
|
|
|
3198
|
|
|
|
|
|
|
|
3199
|
|
|
|
|
|
|
$HELP{'catalog'}=[<<'END']; |
3200
|
|
|
|
|
|
|
usage: catalog [filename] |
3201
|
|
|
|
|
|
|
|
3202
|
|
|
|
|
|
|
description: |
3203
|
|
|
|
|
|
|
Make use of a given XML file as a catalog during all parsing |
3204
|
|
|
|
|
|
|
processes. Using a catalog may significantly speed up parsing |
3205
|
|
|
|
|
|
|
processes if many external resources are loaded into the |
3206
|
|
|
|
|
|
|
parsed documents (such as DTDs or XIncludes). |
3207
|
|
|
|
|
|
|
|
3208
|
|
|
|
|
|
|
END |
3209
|
|
|
|
|
|
|
|
3210
|
|
|
|
|
|
|
|
3211
|
|
|
|
|
|
|
$HELP{'iterate'}=[<<'END']; |
3212
|
|
|
|
|
|
|
usage: iterate [xpath] [block] |
3213
|
|
|
|
|
|
|
|
3214
|
|
|
|
|
|
|
description: |
3215
|
|
|
|
|
|
|
Iterate works very much like a [foreach] loop with the same |
3216
|
|
|
|
|
|
|
[xpath] expression, except that it evaluates the [block] as |
3217
|
|
|
|
|
|
|
soon as a new node matching a given [xpath] is found. As a |
3218
|
|
|
|
|
|
|
limitation, an [xpath] expression used with 'iterate' may |
3219
|
|
|
|
|
|
|
consist of one XPath step only, i.e. it may not contain an |
3220
|
|
|
|
|
|
|
XPath step separator '/'. |
3221
|
|
|
|
|
|
|
|
3222
|
|
|
|
|
|
|
A possible benefit of using 'iterate' instead of [foreach] is |
3223
|
|
|
|
|
|
|
some efficiency when iterating over huge node-sets. Since |
3224
|
|
|
|
|
|
|
'iterate' doesn't compute the resulting node-set in advance, |
3225
|
|
|
|
|
|
|
it doesn't have to 1) allocate extra memory for it and 2) |
3226
|
|
|
|
|
|
|
(more importantly) doesn't have to sort the node-list in the |
3227
|
|
|
|
|
|
|
document order (which tends to be slow on large node-sets, |
3228
|
|
|
|
|
|
|
unless [index] is used). On the other hand, 'iterate' suffers |
3229
|
|
|
|
|
|
|
from a considerable speed penalty since it isn't implemented |
3230
|
|
|
|
|
|
|
in C (unlike libxml2's XPath engine). |
3231
|
|
|
|
|
|
|
|
3232
|
|
|
|
|
|
|
Author's experience shows that, unless [index] is used, |
3233
|
|
|
|
|
|
|
'iterate' beats [foreach] in speed on large node-lists (>=1500 |
3234
|
|
|
|
|
|
|
nodes, but your milage may vary) while [foreach] wins on |
3235
|
|
|
|
|
|
|
smaller node-lists. |
3236
|
|
|
|
|
|
|
|
3237
|
|
|
|
|
|
|
The following two examples give equivalent results. However, |
3238
|
|
|
|
|
|
|
the one using 'iterate' may be faster if the number of nodes |
3239
|
|
|
|
|
|
|
being counted is huge and document order isn't indexed. |
3240
|
|
|
|
|
|
|
|
3241
|
|
|
|
|
|
|
Example: Count inhabitants of the kingdom of Rohan in productive age |
3242
|
|
|
|
|
|
|
|
3243
|
|
|
|
|
|
|
cd rohan/inhabitants; |
3244
|
|
|
|
|
|
|
iterate child::*[@age>=18 and @age<60] { perl $productive++ }; |
3245
|
|
|
|
|
|
|
echo "$productive inhabitants in productive age"; |
3246
|
|
|
|
|
|
|
|
3247
|
|
|
|
|
|
|
Example: Using XPath |
3248
|
|
|
|
|
|
|
|
3249
|
|
|
|
|
|
|
$productive=count(rohan/inhabitants/*[@age>=18 and @age<60]); |
3250
|
|
|
|
|
|
|
echo "$productive inhabitants in productive age"; |
3251
|
|
|
|
|
|
|
|
3252
|
|
|
|
|
|
|
Hint: use e.g. '| time cut' pipe-line redirection to benchmark |
3253
|
|
|
|
|
|
|
a XSH2 command on a UNIX system. |
3254
|
|
|
|
|
|
|
|
3255
|
|
|
|
|
|
|
see also: foreach index next prev last |
3256
|
|
|
|
|
|
|
|
3257
|
|
|
|
|
|
|
END |
3258
|
|
|
|
|
|
|
|
3259
|
|
|
|
|
|
|
|
3260
|
|
|
|
|
|
|
$HELP{'register-namespace'}=[<<'END']; |
3261
|
|
|
|
|
|
|
usage: register-namespace [expression] [expression] |
3262
|
|
|
|
|
|
|
|
3263
|
|
|
|
|
|
|
aliases: regns |
3264
|
|
|
|
|
|
|
|
3265
|
|
|
|
|
|
|
description: |
3266
|
|
|
|
|
|
|
Registers the first argument as a prefix for the namespace |
3267
|
|
|
|
|
|
|
given in the second argument. The prefix can later be used in |
3268
|
|
|
|
|
|
|
XPath expressions. |
3269
|
|
|
|
|
|
|
|
3270
|
|
|
|
|
|
|
END |
3271
|
|
|
|
|
|
|
|
3272
|
|
|
|
|
|
|
$HELP{'regns'}=$HELP{'register-namespace'}; |
3273
|
|
|
|
|
|
|
|
3274
|
|
|
|
|
|
|
$HELP{'unregister-namespace'}=[<<'END']; |
3275
|
|
|
|
|
|
|
usage: unregister-namespace [expression] |
3276
|
|
|
|
|
|
|
|
3277
|
|
|
|
|
|
|
aliases: unregns |
3278
|
|
|
|
|
|
|
|
3279
|
|
|
|
|
|
|
description: |
3280
|
|
|
|
|
|
|
Unregisters given namespace prefix previously registered using |
3281
|
|
|
|
|
|
|
[register-namespace]. The prefix can no longer be used in |
3282
|
|
|
|
|
|
|
XPath expressions unless declared within the current scope of |
3283
|
|
|
|
|
|
|
the queried document. |
3284
|
|
|
|
|
|
|
|
3285
|
|
|
|
|
|
|
END |
3286
|
|
|
|
|
|
|
|
3287
|
|
|
|
|
|
|
$HELP{'unregns'}=$HELP{'unregister-namespace'}; |
3288
|
|
|
|
|
|
|
|
3289
|
|
|
|
|
|
|
$HELP{'register-xhtml-namespace'}=[<<'END']; |
3290
|
|
|
|
|
|
|
usage: register-xhtml-namespace [expression] |
3291
|
|
|
|
|
|
|
|
3292
|
|
|
|
|
|
|
aliases: regns-xhtml |
3293
|
|
|
|
|
|
|
|
3294
|
|
|
|
|
|
|
description: |
3295
|
|
|
|
|
|
|
Registers a prefix for the XHTML namespace |
3296
|
|
|
|
|
|
|
'http://www.w3.org/1999/xhtml'. The prefix can later be used |
3297
|
|
|
|
|
|
|
in XPath expressions. |
3298
|
|
|
|
|
|
|
|
3299
|
|
|
|
|
|
|
END |
3300
|
|
|
|
|
|
|
|
3301
|
|
|
|
|
|
|
$HELP{'regns-xhtml'}=$HELP{'register-xhtml-namespace'}; |
3302
|
|
|
|
|
|
|
|
3303
|
|
|
|
|
|
|
$HELP{'register-xsh-namespace'}=[<<'END']; |
3304
|
|
|
|
|
|
|
usage: register-xsh-namespace [expression] |
3305
|
|
|
|
|
|
|
|
3306
|
|
|
|
|
|
|
aliases: regns-xsh |
3307
|
|
|
|
|
|
|
|
3308
|
|
|
|
|
|
|
description: |
3309
|
|
|
|
|
|
|
Registers a new prefix for the XSH2 namespace |
3310
|
|
|
|
|
|
|
'http://xsh.sourceforge.net/xsh/'. The prefix can later be |
3311
|
|
|
|
|
|
|
used in XPath expressions. Note, that XSH2 namespace is by |
3312
|
|
|
|
|
|
|
default registered with the prefix 'xsh'. This command is |
3313
|
|
|
|
|
|
|
thus, in general, useful only when some document uses 'xsh' |
3314
|
|
|
|
|
|
|
prefix for a different namespace or if you want a shorter |
3315
|
|
|
|
|
|
|
prefix. |
3316
|
|
|
|
|
|
|
|
3317
|
|
|
|
|
|
|
END |
3318
|
|
|
|
|
|
|
|
3319
|
|
|
|
|
|
|
$HELP{'regns-xsh'}=$HELP{'register-xsh-namespace'}; |
3320
|
|
|
|
|
|
|
|
3321
|
|
|
|
|
|
|
$HELP{'register-function'}=[<<'END']; |
3322
|
|
|
|
|
|
|
usage: register-function [expression] [perl-code] |
3323
|
|
|
|
|
|
|
|
3324
|
|
|
|
|
|
|
aliases: function regfunc |
3325
|
|
|
|
|
|
|
|
3326
|
|
|
|
|
|
|
description: |
3327
|
|
|
|
|
|
|
EXPERIMENTAL! |
3328
|
|
|
|
|
|
|
|
3329
|
|
|
|
|
|
|
Registers a given perl code as a new XPath extension function |
3330
|
|
|
|
|
|
|
under a name provided in the first argument. XML::LibXML DOM |
3331
|
|
|
|
|
|
|
API as well as all Perl functions pre-defined in the |
3332
|
|
|
|
|
|
|
XML::XSH2::Map namespace may be used in the perl code for |
3333
|
|
|
|
|
|
|
object processing. If the name contains a colon, then the |
3334
|
|
|
|
|
|
|
first part before the colon must be a registered namespace |
3335
|
|
|
|
|
|
|
prefix (see [register-namespace]) and the function is |
3336
|
|
|
|
|
|
|
registered within the corresponding namespace. |
3337
|
|
|
|
|
|
|
|
3338
|
|
|
|
|
|
|
END |
3339
|
|
|
|
|
|
|
|
3340
|
|
|
|
|
|
|
$HELP{'function'}=$HELP{'register-function'}; |
3341
|
|
|
|
|
|
|
$HELP{'regfunc'}=$HELP{'register-function'}; |
3342
|
|
|
|
|
|
|
|
3343
|
|
|
|
|
|
|
$HELP{'unregister-function'}=[<<'END']; |
3344
|
|
|
|
|
|
|
usage: unregister-function [expression] |
3345
|
|
|
|
|
|
|
|
3346
|
|
|
|
|
|
|
aliases: unregfunc |
3347
|
|
|
|
|
|
|
|
3348
|
|
|
|
|
|
|
description: |
3349
|
|
|
|
|
|
|
EXPERIMENTAL! Unregister XPath extension function of a given |
3350
|
|
|
|
|
|
|
name previously registered using [register-function]. |
3351
|
|
|
|
|
|
|
|
3352
|
|
|
|
|
|
|
END |
3353
|
|
|
|
|
|
|
|
3354
|
|
|
|
|
|
|
$HELP{'unregfunc'}=$HELP{'unregister-function'}; |
3355
|
|
|
|
|
|
|
|
3356
|
|
|
|
|
|
|
$HELP{'stream'}=[<<'END']; |
3357
|
|
|
|
|
|
|
usage: stream [ --input-file|:f [filename] | |
3358
|
|
|
|
|
|
|
--input-pipe|:p [filename] | |
3359
|
|
|
|
|
|
|
--input-string|:s [expression]] |
3360
|
|
|
|
|
|
|
[ --output-file|:F [filename] | |
3361
|
|
|
|
|
|
|
--output-pipe|:P [filename] | |
3362
|
|
|
|
|
|
|
--output-string|:S [$variable] | |
3363
|
|
|
|
|
|
|
--no-output|:N ] |
3364
|
|
|
|
|
|
|
select [xpath] [block] |
3365
|
|
|
|
|
|
|
[ select [xpath] [block] ... ] |
3366
|
|
|
|
|
|
|
|
3367
|
|
|
|
|
|
|
description: |
3368
|
|
|
|
|
|
|
EXPERIMENTAL! This command provides a memory efficient (though |
3369
|
|
|
|
|
|
|
slower) way to process selected parts of an XML document with |
3370
|
|
|
|
|
|
|
XSH2. A streaming XML parser (SAX parser) is used to parse the |
3371
|
|
|
|
|
|
|
input. The parser has two states which will be referred to as |
3372
|
|
|
|
|
|
|
A and B below. The initial state of the parser is A. |
3373
|
|
|
|
|
|
|
|
3374
|
|
|
|
|
|
|
In the state A, only a limited vertical portion of the DOM |
3375
|
|
|
|
|
|
|
tree is built. All XML data coming from the input stream other |
3376
|
|
|
|
|
|
|
than start-tags are immediately copied to the output stream. |
3377
|
|
|
|
|
|
|
If a new start-tag of an element arrives, a new node is |
3378
|
|
|
|
|
|
|
created in the tree. All siblings of the newly created node |
3379
|
|
|
|
|
|
|
are removed. Thus, in the state A, there is exactly one node |
3380
|
|
|
|
|
|
|
on every level of the tree. After a node is added to the tree, |
3381
|
|
|
|
|
|
|
all the [xpath] expressions following the 'select' keyword are |
3382
|
|
|
|
|
|
|
checked. If none matches, the parser remains in state A and |
3383
|
|
|
|
|
|
|
copies the start-tag to the output stream. Otherwise, the |
3384
|
|
|
|
|
|
|
first expression that matches is remembered and the parser |
3385
|
|
|
|
|
|
|
changes its state to B. |
3386
|
|
|
|
|
|
|
|
3387
|
|
|
|
|
|
|
In state B the parser builds a complete DOM subtree of the |
3388
|
|
|
|
|
|
|
element that was last added to the tree before the parser |
3389
|
|
|
|
|
|
|
changed its state from A to B. No data are sent to the output |
3390
|
|
|
|
|
|
|
at this stage. When the subtree is complete (i.e. the |
3391
|
|
|
|
|
|
|
corresponding end-tag for its topmost element is encountered), |
3392
|
|
|
|
|
|
|
the [block] of instructions following the [xpath] expression |
3393
|
|
|
|
|
|
|
that matched is invoked with the root element of the subtree |
3394
|
|
|
|
|
|
|
as the current context node. The commands in [block] are |
3395
|
|
|
|
|
|
|
allowed to transform the whole element subtree or even to |
3396
|
|
|
|
|
|
|
replace it with a different DOM subtree or subtrees. They |
3397
|
|
|
|
|
|
|
must, however, leave intact all ancestor nodes of the subtree. |
3398
|
|
|
|
|
|
|
Failing to do so can result in an error or unpredictable |
3399
|
|
|
|
|
|
|
results. |
3400
|
|
|
|
|
|
|
|
3401
|
|
|
|
|
|
|
After the subtree processing [block] returns, all subtrees |
3402
|
|
|
|
|
|
|
that now appear in the DOM tree in the place of the original |
3403
|
|
|
|
|
|
|
subtree are serialized to the output stream. After that, they |
3404
|
|
|
|
|
|
|
are deleted and the parser returns to state A. |
3405
|
|
|
|
|
|
|
|
3406
|
|
|
|
|
|
|
Note that this type of processing highly limits the amount of |
3407
|
|
|
|
|
|
|
information the selecting XPath expressions can use. The first |
3408
|
|
|
|
|
|
|
notable fact is, that elements can not be selected by their |
3409
|
|
|
|
|
|
|
content. The only information present in the tree at the time |
3410
|
|
|
|
|
|
|
of the XPath evaluation is the element's name and attributes |
3411
|
|
|
|
|
|
|
plus the same information for all its ancestors (there is no |
3412
|
|
|
|
|
|
|
information at all about its possible child nodes nor of the |
3413
|
|
|
|
|
|
|
node's position within the list of its siblings). |
3414
|
|
|
|
|
|
|
|
3415
|
|
|
|
|
|
|
The input parameters below are mutually exclusive. If non is |
3416
|
|
|
|
|
|
|
given, standard input is processed. |
3417
|
|
|
|
|
|
|
|
3418
|
|
|
|
|
|
|
'--input-file' or ':f' instructs the processor to stream from |
3419
|
|
|
|
|
|
|
a given file. |
3420
|
|
|
|
|
|
|
|
3421
|
|
|
|
|
|
|
'--input-pipe' or ':p' instructs the processor to stream the |
3422
|
|
|
|
|
|
|
output of a given a command. |
3423
|
|
|
|
|
|
|
|
3424
|
|
|
|
|
|
|
'--input-string' or ':s' instructs the processor to use the |
3425
|
|
|
|
|
|
|
result of a given expression as the input to be processed. |
3426
|
|
|
|
|
|
|
|
3427
|
|
|
|
|
|
|
The output parameters below are mutually exclusive. If none is |
3428
|
|
|
|
|
|
|
given, standard output is used. |
3429
|
|
|
|
|
|
|
|
3430
|
|
|
|
|
|
|
'--output-file' or ':F' instructs the processor to save the |
3431
|
|
|
|
|
|
|
output to a given file. |
3432
|
|
|
|
|
|
|
|
3433
|
|
|
|
|
|
|
'--output-pipe' or ':P' instructs the processor to pipe the |
3434
|
|
|
|
|
|
|
output to a given command. |
3435
|
|
|
|
|
|
|
|
3436
|
|
|
|
|
|
|
'--output-string' or ':S' followed by a variable name |
3437
|
|
|
|
|
|
|
instructs the processor to store the result in the given |
3438
|
|
|
|
|
|
|
variable. |
3439
|
|
|
|
|
|
|
|
3440
|
|
|
|
|
|
|
'--no-output' or ':N' instructs the processor to throw the |
3441
|
|
|
|
|
|
|
result away. |
3442
|
|
|
|
|
|
|
|
3443
|
|
|
|
|
|
|
END |
3444
|
|
|
|
|
|
|
|
3445
|
|
|
|
|
|
|
|
3446
|
|
|
|
|
|
|
$HELP{'namespaces'}=[<<'END']; |
3447
|
|
|
|
|
|
|
usage: namespaces [--registered|:r] [[expression]] |
3448
|
|
|
|
|
|
|
|
3449
|
|
|
|
|
|
|
description: |
3450
|
|
|
|
|
|
|
For each node in a given node-list lists all namespaces that |
3451
|
|
|
|
|
|
|
are valid the scope of the node. Namespaces are listed in the |
3452
|
|
|
|
|
|
|
form of 'xmlns:prefix="uri"' declarations, preceded by a |
3453
|
|
|
|
|
|
|
canonical xpath of the corresponding node on a separate line. |
3454
|
|
|
|
|
|
|
|
3455
|
|
|
|
|
|
|
If '--registered' or ':r' flag is used, list also namespaces |
3456
|
|
|
|
|
|
|
registered with the [register-namespace] command in XSH |
3457
|
|
|
|
|
|
|
syntax. |
3458
|
|
|
|
|
|
|
|
3459
|
|
|
|
|
|
|
If called without the '--registered' flag and no [xpath] is |
3460
|
|
|
|
|
|
|
given, lists namespaces in the scope of the current node. |
3461
|
|
|
|
|
|
|
|
3462
|
|
|
|
|
|
|
END |
3463
|
|
|
|
|
|
|
|
3464
|
|
|
|
|
|
|
|
3465
|
|
|
|
|
|
|
$HELP{'xpath-completion'}=[<<'END']; |
3466
|
|
|
|
|
|
|
usage: xpath-completion [expression] |
3467
|
|
|
|
|
|
|
|
3468
|
|
|
|
|
|
|
aliases: xpath_completion |
3469
|
|
|
|
|
|
|
|
3470
|
|
|
|
|
|
|
description: |
3471
|
|
|
|
|
|
|
If the [expression] is non-zero, enable the TAB completion for |
3472
|
|
|
|
|
|
|
[xpath] expansions in the interactive shell mode, disable it |
3473
|
|
|
|
|
|
|
otherwise. Defaults to on. |
3474
|
|
|
|
|
|
|
|
3475
|
|
|
|
|
|
|
This command is equivalent to setting the '$XPATH_COMPLETION' |
3476
|
|
|
|
|
|
|
variable. |
3477
|
|
|
|
|
|
|
|
3478
|
|
|
|
|
|
|
END |
3479
|
|
|
|
|
|
|
|
3480
|
|
|
|
|
|
|
$HELP{'xpath_completion'}=$HELP{'xpath-completion'}; |
3481
|
|
|
|
|
|
|
|
3482
|
|
|
|
|
|
|
$HELP{'xpath-axis-completion'}=[<<'END']; |
3483
|
|
|
|
|
|
|
usage: xpath-axis-completion [expression] |
3484
|
|
|
|
|
|
|
|
3485
|
|
|
|
|
|
|
aliases: xpath_axis_completion |
3486
|
|
|
|
|
|
|
|
3487
|
|
|
|
|
|
|
description: |
3488
|
|
|
|
|
|
|
The following values are allowed: 'always', 'never', |
3489
|
|
|
|
|
|
|
'when-empty'. Note, that all other values (including 1) work |
3490
|
|
|
|
|
|
|
as 'never'! |
3491
|
|
|
|
|
|
|
|
3492
|
|
|
|
|
|
|
If the [expression] evaluates to 'always', TAB completion for |
3493
|
|
|
|
|
|
|
XPath expressions always includes axis names. |
3494
|
|
|
|
|
|
|
|
3495
|
|
|
|
|
|
|
If the [expression] evaluates to 'when-empty', the TAB |
3496
|
|
|
|
|
|
|
completion list for XPath expressions includes axis names only |
3497
|
|
|
|
|
|
|
if no element name matches the completion. |
3498
|
|
|
|
|
|
|
|
3499
|
|
|
|
|
|
|
If the [expression] evaluates to 'never', the TAB completion |
3500
|
|
|
|
|
|
|
list for XPath expressions never includes axis names. |
3501
|
|
|
|
|
|
|
|
3502
|
|
|
|
|
|
|
The default value for this option is 'always'. |
3503
|
|
|
|
|
|
|
|
3504
|
|
|
|
|
|
|
This command is equivalent to setting the |
3505
|
|
|
|
|
|
|
'$XPATH_AXIS_COMPLETION' variable. |
3506
|
|
|
|
|
|
|
|
3507
|
|
|
|
|
|
|
END |
3508
|
|
|
|
|
|
|
|
3509
|
|
|
|
|
|
|
$HELP{'xpath_axis_completion'}=$HELP{'xpath-axis-completion'}; |
3510
|
|
|
|
|
|
|
|
3511
|
|
|
|
|
|
|
$HELP{'doc-info'}=[<<'END']; |
3512
|
|
|
|
|
|
|
usage: doc-info [[document]] |
3513
|
|
|
|
|
|
|
|
3514
|
|
|
|
|
|
|
aliases: doc_info |
3515
|
|
|
|
|
|
|
|
3516
|
|
|
|
|
|
|
description: |
3517
|
|
|
|
|
|
|
In the present implementation, this command displays |
3518
|
|
|
|
|
|
|
information provided in the '' declaration of a |
3519
|
|
|
|
|
|
|
document: 'version, encoding, standalone', plus information |
3520
|
|
|
|
|
|
|
about level of 'gzip' compression of the original XML file and |
3521
|
|
|
|
|
|
|
the original XML file URI. |
3522
|
|
|
|
|
|
|
|
3523
|
|
|
|
|
|
|
see also: set-enc set-standalone |
3524
|
|
|
|
|
|
|
|
3525
|
|
|
|
|
|
|
END |
3526
|
|
|
|
|
|
|
|
3527
|
|
|
|
|
|
|
$HELP{'doc_info'}=$HELP{'doc-info'}; |
3528
|
|
|
|
|
|
|
|
3529
|
|
|
|
|
|
|
$HELP{'xpath-extensions'}=[<<'END']; |
3530
|
|
|
|
|
|
|
usage: xpath-extensions [[expression]] |
3531
|
|
|
|
|
|
|
|
3532
|
|
|
|
|
|
|
aliases: xpath_extensions |
3533
|
|
|
|
|
|
|
|
3534
|
|
|
|
|
|
|
description: |
3535
|
|
|
|
|
|
|
'xpath-extensions' remaps all extra XPath extension functions |
3536
|
|
|
|
|
|
|
provided by XSH2 (which by default belong to the namespace |
3537
|
|
|
|
|
|
|
'http://xsh.sourceforge.net/xsh/') to a new namespace given by |
3538
|
|
|
|
|
|
|
[expression]. If the argument is omitted, the functions are |
3539
|
|
|
|
|
|
|
re-registered without any namespace, so that they may be |
3540
|
|
|
|
|
|
|
called without a namespace prefix, just by their function |
3541
|
|
|
|
|
|
|
names. This quite convenient. |
3542
|
|
|
|
|
|
|
|
3543
|
|
|
|
|
|
|
Example: |
3544
|
|
|
|
|
|
|
xpath-extensions; |
3545
|
|
|
|
|
|
|
ls grep(//word,"^.*tion$"); |
3546
|
|
|
|
|
|
|
|
3547
|
|
|
|
|
|
|
see also: set-enc set-standalone |
3548
|
|
|
|
|
|
|
|
3549
|
|
|
|
|
|
|
END |
3550
|
|
|
|
|
|
|
|
3551
|
|
|
|
|
|
|
$HELP{'xpath_extensions'}=$HELP{'xpath-extensions'}; |
3552
|
|
|
|
|
|
|
|
3553
|
|
|
|
|
|
|
$HELP{'lineno'}=[<<'END']; |
3554
|
|
|
|
|
|
|
usage: lineno [[expression]] |
3555
|
|
|
|
|
|
|
|
3556
|
|
|
|
|
|
|
description: |
3557
|
|
|
|
|
|
|
'lineno' command prints line numbers of all nodes in a given |
3558
|
|
|
|
|
|
|
node-list. Note however, that 'libxml2' only stores line |
3559
|
|
|
|
|
|
|
number information for element nodes. |
3560
|
|
|
|
|
|
|
|
3561
|
|
|
|
|
|
|
see also: locate |
3562
|
|
|
|
|
|
|
|
3563
|
|
|
|
|
|
|
END |
3564
|
|
|
|
|
|
|
|
3565
|
|
|
|
|
|
|
|
3566
|
|
|
|
|
|
|
$HELP{'edit-string'}=[<<'END']; |
3567
|
|
|
|
|
|
|
usage: edit-string [--editor|:E [filename]] |
3568
|
|
|
|
|
|
|
[--encoding|:e [encoding]] |
3569
|
|
|
|
|
|
|
[--allow-empty|:0] [expression] |
3570
|
|
|
|
|
|
|
|
3571
|
|
|
|
|
|
|
description: |
3572
|
|
|
|
|
|
|
Evaluating given [expression] to a string, save it in a |
3573
|
|
|
|
|
|
|
temporary file, open the file an external editor as a plain |
3574
|
|
|
|
|
|
|
text, and when the editor exits, read and return the result. |
3575
|
|
|
|
|
|
|
The '--editor' (':E') parameter can be used to provide an |
3576
|
|
|
|
|
|
|
editor command, whereas '--encoding' (':e') can be used to |
3577
|
|
|
|
|
|
|
specify character encoding used for communication with the |
3578
|
|
|
|
|
|
|
editor. If the result is empty, the interactive XSH2 shell |
3579
|
|
|
|
|
|
|
asks user for confirmation before returning the result in |
3580
|
|
|
|
|
|
|
order to prevent data loss due to some unexpected error. To |
3581
|
|
|
|
|
|
|
suppress this feature, use '--allow-empty' or ':0' flag. |
3582
|
|
|
|
|
|
|
|
3583
|
|
|
|
|
|
|
END |
3584
|
|
|
|
|
|
|
|
3585
|
|
|
|
|
|
|
|
3586
|
|
|
|
|
|
|
$HELP{'edit'}=[<<'END']; |
3587
|
|
|
|
|
|
|
usage: edit [--editor|:E [filename]] |
3588
|
|
|
|
|
|
|
[--all|:A] [--noindent|:n] [--recover|:r] [--keep-blanks|:k] |
3589
|
|
|
|
|
|
|
[--allow-empty|:0] [--no-coment|:q] [--encoding|:e [encoding]] [expression] |
3590
|
|
|
|
|
|
|
|
3591
|
|
|
|
|
|
|
description: |
3592
|
|
|
|
|
|
|
This command may be used to interactively edit parts of a XML |
3593
|
|
|
|
|
|
|
document directly in your favorite editor. |
3594
|
|
|
|
|
|
|
|
3595
|
|
|
|
|
|
|
A given [expression] is evaluated to a node-list and the first |
3596
|
|
|
|
|
|
|
the first resulting node is opened in an external editor as a |
3597
|
|
|
|
|
|
|
XML fragment. When the editor exits, the (possibly modified) |
3598
|
|
|
|
|
|
|
fragment is parsed and returned to the original document. |
3599
|
|
|
|
|
|
|
Unless '--no-comment' (':q') flag is used, the XML fragment is |
3600
|
|
|
|
|
|
|
preceded with a XML comment specifying canonical XPath of the |
3601
|
|
|
|
|
|
|
node being edited. |
3602
|
|
|
|
|
|
|
|
3603
|
|
|
|
|
|
|
The command returns a node-list consisting of nodes that |
3604
|
|
|
|
|
|
|
resulted from parsing the individual edits. |
3605
|
|
|
|
|
|
|
|
3606
|
|
|
|
|
|
|
'--editor' or ':E' option may be used to specify external |
3607
|
|
|
|
|
|
|
editor command. If not specified, environment variables |
3608
|
|
|
|
|
|
|
'EDITOR' and 'VISUAL' are tried first, then 'vi' editor is |
3609
|
|
|
|
|
|
|
used as a fallback. |
3610
|
|
|
|
|
|
|
|
3611
|
|
|
|
|
|
|
If '--all' or ':A' flag is present, all nodes from the |
3612
|
|
|
|
|
|
|
node-list are opened in the editor, one at a time. |
3613
|
|
|
|
|
|
|
|
3614
|
|
|
|
|
|
|
If '--recover' or ':r' is specified, the parser tries to |
3615
|
|
|
|
|
|
|
recover from possible syntax errors when parsing the resulting |
3616
|
|
|
|
|
|
|
XML. |
3617
|
|
|
|
|
|
|
|
3618
|
|
|
|
|
|
|
'--keep-blanks' or ':b' option may be used to force the parser |
3619
|
|
|
|
|
|
|
to include ignorable white space. |
3620
|
|
|
|
|
|
|
|
3621
|
|
|
|
|
|
|
If the result saved by the editor is empty, the interactive |
3622
|
|
|
|
|
|
|
XSH2 shell asks user to confirm this was correct. This |
3623
|
|
|
|
|
|
|
confirmation can be suppressed using '--allow-empty' or ':0' |
3624
|
|
|
|
|
|
|
(zero) options. |
3625
|
|
|
|
|
|
|
|
3626
|
|
|
|
|
|
|
The '--encoding' or ':e' parameter can be used to specify |
3627
|
|
|
|
|
|
|
character encoding to use when communicating with the external |
3628
|
|
|
|
|
|
|
editor. |
3629
|
|
|
|
|
|
|
|
3630
|
|
|
|
|
|
|
Example: Edit all chapter elements (one by one) with emacs |
3631
|
|
|
|
|
|
|
|
3632
|
|
|
|
|
|
|
edit --editor 'emacs -nw' --encoding iso-8859-1 --all //chapter |
3633
|
|
|
|
|
|
|
|
3634
|
|
|
|
|
|
|
END |
3635
|
|
|
|
|
|
|
|
3636
|
|
|
|
|
|
|
|
3637
|
|
|
|
|
|
|
$HELP{'xsh:doc'}=[<<'END']; |
3638
|
|
|
|
|
|
|
usage: node-set xsh:doc(node-set) |
3639
|
|
|
|
|
|
|
|
3640
|
|
|
|
|
|
|
description: |
3641
|
|
|
|
|
|
|
Returns a node-set consisting of the owner document nodes of |
3642
|
|
|
|
|
|
|
all nodes in the given node-set. |
3643
|
|
|
|
|
|
|
|
3644
|
|
|
|
|
|
|
END |
3645
|
|
|
|
|
|
|
|
3646
|
|
|
|
|
|
|
|
3647
|
|
|
|
|
|
|
$HELP{'xsh:document-uri'}=[<<'END']; |
3648
|
|
|
|
|
|
|
usage: string xsh:document-uri(node-set?) |
3649
|
|
|
|
|
|
|
|
3650
|
|
|
|
|
|
|
description: |
3651
|
|
|
|
|
|
|
Returns URI of the document containing the first node in the |
3652
|
|
|
|
|
|
|
given node-set. If called without arguments, or if the |
3653
|
|
|
|
|
|
|
node-set is empty, returns filename of the document containing |
3654
|
|
|
|
|
|
|
the current node. |
3655
|
|
|
|
|
|
|
|
3656
|
|
|
|
|
|
|
END |
3657
|
|
|
|
|
|
|
|
3658
|
|
|
|
|
|
|
|
3659
|
|
|
|
|
|
|
$HELP{'xsh:filename'}=[<<'END']; |
3660
|
|
|
|
|
|
|
usage: string xsh:filename(node-set?) |
3661
|
|
|
|
|
|
|
|
3662
|
|
|
|
|
|
|
description: |
3663
|
|
|
|
|
|
|
Same as xsh:document-uri(); |
3664
|
|
|
|
|
|
|
|
3665
|
|
|
|
|
|
|
END |
3666
|
|
|
|
|
|
|
|
3667
|
|
|
|
|
|
|
|
3668
|
|
|
|
|
|
|
$HELP{'xsh:base-uri'}=[<<'END']; |
3669
|
|
|
|
|
|
|
usage: string xsh:base-uri(node-set?) |
3670
|
|
|
|
|
|
|
|
3671
|
|
|
|
|
|
|
description: |
3672
|
|
|
|
|
|
|
Returns base URI of the first node in the node-set (or the |
3673
|
|
|
|
|
|
|
current node). The function should work on both XML and HTML |
3674
|
|
|
|
|
|
|
documents even if base mechanisms for these are completely |
3675
|
|
|
|
|
|
|
different. It returns the base as defined in RFC 2396 sections |
3676
|
|
|
|
|
|
|
"5.1.1. Base URI within Document Content" and "5.1.2. Base URI |
3677
|
|
|
|
|
|
|
from the Encapsulating Entity". However it does not return the |
3678
|
|
|
|
|
|
|
document base (5.1.3), use document-uri() for this. |
3679
|
|
|
|
|
|
|
|
3680
|
|
|
|
|
|
|
END |
3681
|
|
|
|
|
|
|
|
3682
|
|
|
|
|
|
|
|
3683
|
|
|
|
|
|
|
$HELP{'xsh:resolve-uri'}=[<<'END']; |
3684
|
|
|
|
|
|
|
usage: string xsh:resolve-uri(string, string?) |
3685
|
|
|
|
|
|
|
|
3686
|
|
|
|
|
|
|
description: |
3687
|
|
|
|
|
|
|
This function takes one or two arguments: a relative URI and |
3688
|
|
|
|
|
|
|
an optional base URI. If the first argument is a relative URI |
3689
|
|
|
|
|
|
|
reference, this function resolves it against either the given |
3690
|
|
|
|
|
|
|
base URI, if given (which is assumed to be an absolute URI) |
3691
|
|
|
|
|
|
|
or, if base URI not given, against the URI of the current |
3692
|
|
|
|
|
|
|
working directory. If the first argument is an absolute URI |
3693
|
|
|
|
|
|
|
reference, it is returned unchanged. |
3694
|
|
|
|
|
|
|
|
3695
|
|
|
|
|
|
|
If the first argument is the zero-length string, returns the |
3696
|
|
|
|
|
|
|
base URI if given and the URI of the current working directory |
3697
|
|
|
|
|
|
|
otherwise. |
3698
|
|
|
|
|
|
|
|
3699
|
|
|
|
|
|
|
Note: Resolving a URI does not dereference it (download the |
3700
|
|
|
|
|
|
|
referenced content); it is merely a syntactic operation on two |
3701
|
|
|
|
|
|
|
character strings. |
3702
|
|
|
|
|
|
|
|
3703
|
|
|
|
|
|
|
END |
3704
|
|
|
|
|
|
|
|
3705
|
|
|
|
|
|
|
|
3706
|
|
|
|
|
|
|
$HELP{'xsh:lineno'}=[<<'END']; |
3707
|
|
|
|
|
|
|
usage: node-set xsh:lineno(node-set) |
3708
|
|
|
|
|
|
|
|
3709
|
|
|
|
|
|
|
description: |
3710
|
|
|
|
|
|
|
Returns line number of the occurrence of the first node in the |
3711
|
|
|
|
|
|
|
given node-set in its original XML document (if available). |
3712
|
|
|
|
|
|
|
|
3713
|
|
|
|
|
|
|
END |
3714
|
|
|
|
|
|
|
|
3715
|
|
|
|
|
|
|
|
3716
|
|
|
|
|
|
|
$HELP{'xsh:var'}=[<<'END']; |
3717
|
|
|
|
|
|
|
usage: node-set xsh:var(string NAME) |
3718
|
|
|
|
|
|
|
|
3719
|
|
|
|
|
|
|
description: |
3720
|
|
|
|
|
|
|
Returns a node-set consisting of nodes stored in a XSH2 |
3721
|
|
|
|
|
|
|
node-list variable named 'NAME'. |
3722
|
|
|
|
|
|
|
|
3723
|
|
|
|
|
|
|
END |
3724
|
|
|
|
|
|
|
|
3725
|
|
|
|
|
|
|
|
3726
|
|
|
|
|
|
|
$HELP{'xsh:matches'}=[<<'END']; |
3727
|
|
|
|
|
|
|
usage: boolean xsh:matches(string STR,string PATTERN) |
3728
|
|
|
|
|
|
|
|
3729
|
|
|
|
|
|
|
description: |
3730
|
|
|
|
|
|
|
Returns 'true' if 'STR' matches the regular expression |
3731
|
|
|
|
|
|
|
'PATTERN'. Otherwise returns 'false'. |
3732
|
|
|
|
|
|
|
|
3733
|
|
|
|
|
|
|
END |
3734
|
|
|
|
|
|
|
|
3735
|
|
|
|
|
|
|
|
3736
|
|
|
|
|
|
|
$HELP{'xsh:match'}=[<<'END']; |
3737
|
|
|
|
|
|
|
usage: node-set xsh:match(string STR,string PATTERN,string OPTIONS) |
3738
|
|
|
|
|
|
|
|
3739
|
|
|
|
|
|
|
description: |
3740
|
|
|
|
|
|
|
Searches a given string for a pattern match specified by a |
3741
|
|
|
|
|
|
|
regular expression 'PATTERN' and returns a node-set consisting |
3742
|
|
|
|
|
|
|
of '' elements containing portions of the string |
3743
|
|
|
|
|
|
|
matched by the pattern subexpressions enclosed in parentheses. |
3744
|
|
|
|
|
|
|
The OPTIONS string may contain the following flags: 'c' - do |
3745
|
|
|
|
|
|
|
not reset search position on a failed match when /g is in |
3746
|
|
|
|
|
|
|
effect; 'g' - match globally, i.e. find all occurrences; 'i' - |
3747
|
|
|
|
|
|
|
do case insensitive search; 'm' - treat string as multiple |
3748
|
|
|
|
|
|
|
lines (change "^" and "$" from matching the start or end of |
3749
|
|
|
|
|
|
|
the string to matching the start or end of any line anywhere |
3750
|
|
|
|
|
|
|
within the string) 'o' - compile pattern only once; 's' - |
3751
|
|
|
|
|
|
|
treat string as single line (change "." to match any character |
3752
|
|
|
|
|
|
|
whatsoever, even a newline, which normally it would not |
3753
|
|
|
|
|
|
|
match); 'x' - extend your pattern's legibility by permitting |
3754
|
|
|
|
|
|
|
whitespace and comments. |
3755
|
|
|
|
|
|
|
|
3756
|
|
|
|
|
|
|
END |
3757
|
|
|
|
|
|
|
|
3758
|
|
|
|
|
|
|
|
3759
|
|
|
|
|
|
|
$HELP{'xsh:grep'}=[<<'END']; |
3760
|
|
|
|
|
|
|
usage: node-set xsh:grep(node-set NODES, string PATTERN) |
3761
|
|
|
|
|
|
|
|
3762
|
|
|
|
|
|
|
description: |
3763
|
|
|
|
|
|
|
Returns a node set consisting of those nodes of 'NODES' whose |
3764
|
|
|
|
|
|
|
content (as returned by the built-in XPath function |
3765
|
|
|
|
|
|
|
'string()') matches the regular expression 'PATTERN'. |
3766
|
|
|
|
|
|
|
|
3767
|
|
|
|
|
|
|
END |
3768
|
|
|
|
|
|
|
|
3769
|
|
|
|
|
|
|
|
3770
|
|
|
|
|
|
|
$HELP{'xsh:substr'}=[<<'END']; |
3771
|
|
|
|
|
|
|
usage: string xsh:substr(string STR,float OFFSET,[float LENGTH]) |
3772
|
|
|
|
|
|
|
|
3773
|
|
|
|
|
|
|
description: |
3774
|
|
|
|
|
|
|
Extracts a substring out of 'STR' and returns it. First |
3775
|
|
|
|
|
|
|
character is at offset 0. |
3776
|
|
|
|
|
|
|
|
3777
|
|
|
|
|
|
|
If 'OFFSET' is negative, starts that far from the end of the |
3778
|
|
|
|
|
|
|
string. |
3779
|
|
|
|
|
|
|
|
3780
|
|
|
|
|
|
|
If 'LENGTH' is omitted, returns everything to the end of the |
3781
|
|
|
|
|
|
|
string. If 'LENGTH' is negative, leaves that many characters |
3782
|
|
|
|
|
|
|
off the end of the string. |
3783
|
|
|
|
|
|
|
|
3784
|
|
|
|
|
|
|
If 'OFFSET' and 'LENGTH' specify a substring that is partly |
3785
|
|
|
|
|
|
|
outside the string, only the part within the string is |
3786
|
|
|
|
|
|
|
returned. If the substring is beyond either end of the string, |
3787
|
|
|
|
|
|
|
substr() returns empty string and produces a warning. |
3788
|
|
|
|
|
|
|
|
3789
|
|
|
|
|
|
|
END |
3790
|
|
|
|
|
|
|
|
3791
|
|
|
|
|
|
|
|
3792
|
|
|
|
|
|
|
$HELP{'xsh:reverse'}=[<<'END']; |
3793
|
|
|
|
|
|
|
usage: string xsh:reverse(string STR) |
3794
|
|
|
|
|
|
|
|
3795
|
|
|
|
|
|
|
description: |
3796
|
|
|
|
|
|
|
Returns a string value same as 'STR' but with all characters |
3797
|
|
|
|
|
|
|
in the opposite order. |
3798
|
|
|
|
|
|
|
|
3799
|
|
|
|
|
|
|
END |
3800
|
|
|
|
|
|
|
|
3801
|
|
|
|
|
|
|
|
3802
|
|
|
|
|
|
|
$HELP{'xsh:lc'}=[<<'END']; |
3803
|
|
|
|
|
|
|
usage: string xsh:lc(string STR) |
3804
|
|
|
|
|
|
|
|
3805
|
|
|
|
|
|
|
description: |
3806
|
|
|
|
|
|
|
Returns a lowercased version of 'STR'. |
3807
|
|
|
|
|
|
|
|
3808
|
|
|
|
|
|
|
END |
3809
|
|
|
|
|
|
|
|
3810
|
|
|
|
|
|
|
|
3811
|
|
|
|
|
|
|
$HELP{'xsh:uc'}=[<<'END']; |
3812
|
|
|
|
|
|
|
usage: string xsh:uc(string STR) |
3813
|
|
|
|
|
|
|
|
3814
|
|
|
|
|
|
|
description: |
3815
|
|
|
|
|
|
|
Returns a uppercased version of 'STR'. |
3816
|
|
|
|
|
|
|
|
3817
|
|
|
|
|
|
|
END |
3818
|
|
|
|
|
|
|
|
3819
|
|
|
|
|
|
|
|
3820
|
|
|
|
|
|
|
$HELP{'xsh:lcfirst'}=[<<'END']; |
3821
|
|
|
|
|
|
|
usage: string xsh:lcfirst(string STR) |
3822
|
|
|
|
|
|
|
|
3823
|
|
|
|
|
|
|
description: |
3824
|
|
|
|
|
|
|
Returns the value of 'STR' with the first character |
3825
|
|
|
|
|
|
|
lowercased. |
3826
|
|
|
|
|
|
|
|
3827
|
|
|
|
|
|
|
END |
3828
|
|
|
|
|
|
|
|
3829
|
|
|
|
|
|
|
|
3830
|
|
|
|
|
|
|
$HELP{'xsh:ucfirst'}=[<<'END']; |
3831
|
|
|
|
|
|
|
usage: string xsh:ucfirst(string STR) |
3832
|
|
|
|
|
|
|
|
3833
|
|
|
|
|
|
|
description: |
3834
|
|
|
|
|
|
|
Returns the value of 'STR' with the first character |
3835
|
|
|
|
|
|
|
uppercased. |
3836
|
|
|
|
|
|
|
|
3837
|
|
|
|
|
|
|
END |
3838
|
|
|
|
|
|
|
|
3839
|
|
|
|
|
|
|
|
3840
|
|
|
|
|
|
|
$HELP{'xsh:same'}=[<<'END']; |
3841
|
|
|
|
|
|
|
usage: bool xsh:same(node-set N1, node-set N2) |
3842
|
|
|
|
|
|
|
|
3843
|
|
|
|
|
|
|
description: |
3844
|
|
|
|
|
|
|
Returns 'true' if the given node sets both contain the same |
3845
|
|
|
|
|
|
|
node (in XPath, this can also be expressed as |
3846
|
|
|
|
|
|
|
'count(N1|N2)+count(N1)+count(N2)=3'). |
3847
|
|
|
|
|
|
|
|
3848
|
|
|
|
|
|
|
END |
3849
|
|
|
|
|
|
|
|
3850
|
|
|
|
|
|
|
|
3851
|
|
|
|
|
|
|
$HELP{'xsh:max'}=[<<'END']; |
3852
|
|
|
|
|
|
|
usage: float xsh:max(object EXPRESSION, ...) |
3853
|
|
|
|
|
|
|
|
3854
|
|
|
|
|
|
|
description: |
3855
|
|
|
|
|
|
|
Returns the maximum of numeric values computed from given |
3856
|
|
|
|
|
|
|
'EXPRESSION'(s). If 'EXPRESSION' evaluates to a node-set, |
3857
|
|
|
|
|
|
|
string values of individual nodes are used. |
3858
|
|
|
|
|
|
|
|
3859
|
|
|
|
|
|
|
END |
3860
|
|
|
|
|
|
|
|
3861
|
|
|
|
|
|
|
|
3862
|
|
|
|
|
|
|
$HELP{'xsh:min'}=[<<'END']; |
3863
|
|
|
|
|
|
|
usage: float xsh:min(object EXPRESSION, ...) |
3864
|
|
|
|
|
|
|
|
3865
|
|
|
|
|
|
|
description: |
3866
|
|
|
|
|
|
|
Returns the minimum of numeric values computed from given |
3867
|
|
|
|
|
|
|
'EXPRESSION'(s). If 'EXPRESSION' evaluates to a node-set, |
3868
|
|
|
|
|
|
|
string values of individual nodes are used. |
3869
|
|
|
|
|
|
|
|
3870
|
|
|
|
|
|
|
END |
3871
|
|
|
|
|
|
|
|
3872
|
|
|
|
|
|
|
|
3873
|
|
|
|
|
|
|
$HELP{'xsh:strmax'}=[<<'END']; |
3874
|
|
|
|
|
|
|
usage: string xsh:strmax(object EXPRESSION, ...) |
3875
|
|
|
|
|
|
|
|
3876
|
|
|
|
|
|
|
description: |
3877
|
|
|
|
|
|
|
Returns a string value computed as the maximum (in |
3878
|
|
|
|
|
|
|
lexicographical order) of all string values computed from |
3879
|
|
|
|
|
|
|
given 'EXPRESSION'(s). If 'EXPRESSION' evaluates to a |
3880
|
|
|
|
|
|
|
node-set, string values of individual nodes are used. |
3881
|
|
|
|
|
|
|
|
3882
|
|
|
|
|
|
|
END |
3883
|
|
|
|
|
|
|
|
3884
|
|
|
|
|
|
|
|
3885
|
|
|
|
|
|
|
$HELP{'xsh:strmin'}=[<<'END']; |
3886
|
|
|
|
|
|
|
usage: string xsh:strmin(object EXPRESSION, ...) |
3887
|
|
|
|
|
|
|
|
3888
|
|
|
|
|
|
|
description: |
3889
|
|
|
|
|
|
|
Returns a string value computed as the minimum (in |
3890
|
|
|
|
|
|
|
lexicographical order) of all string values computed from |
3891
|
|
|
|
|
|
|
given 'EXPRESSION'(s). If 'EXPRESSION' evaluates to a |
3892
|
|
|
|
|
|
|
node-set, string values of individual nodes are used. |
3893
|
|
|
|
|
|
|
|
3894
|
|
|
|
|
|
|
END |
3895
|
|
|
|
|
|
|
|
3896
|
|
|
|
|
|
|
|
3897
|
|
|
|
|
|
|
$HELP{'xsh:sum'}=[<<'END']; |
3898
|
|
|
|
|
|
|
usage: float xsh:sum(object EXPRESSION, ...) |
3899
|
|
|
|
|
|
|
|
3900
|
|
|
|
|
|
|
description: |
3901
|
|
|
|
|
|
|
Returns the sum of numerical value computed from given |
3902
|
|
|
|
|
|
|
'EXPRESSION'(s). If 'EXPRESSION' evaluates to a node-set, |
3903
|
|
|
|
|
|
|
string values of individual nodes are used. |
3904
|
|
|
|
|
|
|
|
3905
|
|
|
|
|
|
|
END |
3906
|
|
|
|
|
|
|
|
3907
|
|
|
|
|
|
|
|
3908
|
|
|
|
|
|
|
$HELP{'xsh:join'}=[<<'END']; |
3909
|
|
|
|
|
|
|
usage: string xsh:join(string DELIM, object EXPRESSION,...) |
3910
|
|
|
|
|
|
|
|
3911
|
|
|
|
|
|
|
description: |
3912
|
|
|
|
|
|
|
Joins the separate string values computed from 'EXPRESSION'(s) |
3913
|
|
|
|
|
|
|
into a single string with fields separated by the value of |
3914
|
|
|
|
|
|
|
'DELIM', and returns that new string. If 'EXPRESSION' |
3915
|
|
|
|
|
|
|
evaluates to a node-set, joins string values of individual |
3916
|
|
|
|
|
|
|
nodes. |
3917
|
|
|
|
|
|
|
|
3918
|
|
|
|
|
|
|
END |
3919
|
|
|
|
|
|
|
|
3920
|
|
|
|
|
|
|
|
3921
|
|
|
|
|
|
|
$HELP{'xsh:subst'}=[<<'END']; |
3922
|
|
|
|
|
|
|
usage: string xsh:subst(string STR,string REGEXP,string |
3923
|
|
|
|
|
|
|
REPLACEMENT, [string OPTIONS]) |
3924
|
|
|
|
|
|
|
|
3925
|
|
|
|
|
|
|
description: |
3926
|
|
|
|
|
|
|
Acts in the very same way as perl substitution operation |
3927
|
|
|
|
|
|
|
'STRING =~ s/REGEXP/REPLACEMENT/OPTIONS', returning the |
3928
|
|
|
|
|
|
|
resulting string. Searches a string for a pattern, and if |
3929
|
|
|
|
|
|
|
found, replaces that pattern with the replacement text. If the |
3930
|
|
|
|
|
|
|
'REPLACEMENT' string contains a '$' that looks like a |
3931
|
|
|
|
|
|
|
variable, the variable will be interpolated into the |
3932
|
|
|
|
|
|
|
|
3933
|
|
|
|
|
|
|
'REPLACEMENT' at run-time. Options are: |
3934
|
|
|
|
|
|
|
|
3935
|
|
|
|
|
|
|
'e' - evaluate 'REPLACEMENT' as a Perl expression, |
3936
|
|
|
|
|
|
|
|
3937
|
|
|
|
|
|
|
'g' - replace globally, i.e., all occurrences, |
3938
|
|
|
|
|
|
|
|
3939
|
|
|
|
|
|
|
'i' - do case-insensitive pattern matching, |
3940
|
|
|
|
|
|
|
|
3941
|
|
|
|
|
|
|
'm' - treat string as multiple lines, that is, change '^' and |
3942
|
|
|
|
|
|
|
'$' from matching the start or end of the string to matching |
3943
|
|
|
|
|
|
|
the start or end of any line anywhere within the string, |
3944
|
|
|
|
|
|
|
|
3945
|
|
|
|
|
|
|
's' - treat string as single line, that is, change '.' to |
3946
|
|
|
|
|
|
|
match any character whatsoever, even a newline, which normally |
3947
|
|
|
|
|
|
|
it would not match, |
3948
|
|
|
|
|
|
|
|
3949
|
|
|
|
|
|
|
'x' - use extended regular expressions. |
3950
|
|
|
|
|
|
|
|
3951
|
|
|
|
|
|
|
END |
3952
|
|
|
|
|
|
|
|
3953
|
|
|
|
|
|
|
|
3954
|
|
|
|
|
|
|
$HELP{'xsh:sprintf'}=[<<'END']; |
3955
|
|
|
|
|
|
|
usage: string xsh:sprintf(string FORMAT,object EXPRESSION,...) |
3956
|
|
|
|
|
|
|
|
3957
|
|
|
|
|
|
|
description: |
3958
|
|
|
|
|
|
|
Returns a string formatted by the usual 'printf' conventions |
3959
|
|
|
|
|
|
|
of the C library function 'sprintf' and 'sprintf' Perl |
3960
|
|
|
|
|
|
|
function. |
3961
|
|
|
|
|
|
|
|
3962
|
|
|
|
|
|
|
See C documentation for an explanation of the general |
3963
|
|
|
|
|
|
|
principles and Perl documentation for a list of supported |
3964
|
|
|
|
|
|
|
formatting conversions. |
3965
|
|
|
|
|
|
|
|
3966
|
|
|
|
|
|
|
END |
3967
|
|
|
|
|
|
|
|
3968
|
|
|
|
|
|
|
|
3969
|
|
|
|
|
|
|
$HELP{'xsh:serialize'}=[<<'END']; |
3970
|
|
|
|
|
|
|
usage: string xsh:serialize(node-set N,...) |
3971
|
|
|
|
|
|
|
|
3972
|
|
|
|
|
|
|
description: |
3973
|
|
|
|
|
|
|
Serializes nodes of given node-set(s) into XML strings and |
3974
|
|
|
|
|
|
|
returns concatenation of those strings. |
3975
|
|
|
|
|
|
|
|
3976
|
|
|
|
|
|
|
END |
3977
|
|
|
|
|
|
|
|
3978
|
|
|
|
|
|
|
|
3979
|
|
|
|
|
|
|
$HELP{'xsh:parse'}=[<<'END']; |
3980
|
|
|
|
|
|
|
usage: node-set xsh:parse(string XML-STRING) |
3981
|
|
|
|
|
|
|
|
3982
|
|
|
|
|
|
|
description: |
3983
|
|
|
|
|
|
|
This function runs XML parser on 'XML-STRING' and returns a |
3984
|
|
|
|
|
|
|
node-set consisting of the top-level nodes of the resulting |
3985
|
|
|
|
|
|
|
document node. |
3986
|
|
|
|
|
|
|
|
3987
|
|
|
|
|
|
|
END |
3988
|
|
|
|
|
|
|
|
3989
|
|
|
|
|
|
|
|
3990
|
|
|
|
|
|
|
$HELP{'xsh:current'}=[<<'END']; |
3991
|
|
|
|
|
|
|
usage: node-set xsh:current() |
3992
|
|
|
|
|
|
|
|
3993
|
|
|
|
|
|
|
description: |
3994
|
|
|
|
|
|
|
This function (very similar to XSLT 'current()' extension |
3995
|
|
|
|
|
|
|
function) returns a node-set having the current node as its |
3996
|
|
|
|
|
|
|
only member. |
3997
|
|
|
|
|
|
|
|
3998
|
|
|
|
|
|
|
END |
3999
|
|
|
|
|
|
|
|
4000
|
|
|
|
|
|
|
|
4001
|
|
|
|
|
|
|
$HELP{'xsh:path'}=[<<'END']; |
4002
|
|
|
|
|
|
|
usage: string xsh:path(node-set NODE) |
4003
|
|
|
|
|
|
|
|
4004
|
|
|
|
|
|
|
description: |
4005
|
|
|
|
|
|
|
This function returns a string containing canonical XPath |
4006
|
|
|
|
|
|
|
leading to 'NODE'. |
4007
|
|
|
|
|
|
|
|
4008
|
|
|
|
|
|
|
see also: pwd |
4009
|
|
|
|
|
|
|
|
4010
|
|
|
|
|
|
|
END |
4011
|
|
|
|
|
|
|
|
4012
|
|
|
|
|
|
|
|
4013
|
|
|
|
|
|
|
$HELP{'xsh:if'}=[<<'END']; |
4014
|
|
|
|
|
|
|
usage: object xsh:if(object CONDITION, object YES, object NO) |
4015
|
|
|
|
|
|
|
|
4016
|
|
|
|
|
|
|
description: |
4017
|
|
|
|
|
|
|
This function returns the 'YES' object if 'CONDITION' is an |
4018
|
|
|
|
|
|
|
non-empty node-set or a string, boolean or integer evaluating |
4019
|
|
|
|
|
|
|
to non-zero boolean. Otherwise the 'NO' object is returned. |
4020
|
|
|
|
|
|
|
|
4021
|
|
|
|
|
|
|
END |
4022
|
|
|
|
|
|
|
|
4023
|
|
|
|
|
|
|
|
4024
|
|
|
|
|
|
|
$HELP{'xsh:new-attribute'}=[<<'END']; |
4025
|
|
|
|
|
|
|
usage: node-set xsh:new-attribute(string NAME1,string |
4026
|
|
|
|
|
|
|
VALUE1,[string NAME2, string VALUE2, ...]) |
4027
|
|
|
|
|
|
|
|
4028
|
|
|
|
|
|
|
description: |
4029
|
|
|
|
|
|
|
Return a node-set consisting of newly created attribute nodes |
4030
|
|
|
|
|
|
|
with given names and respective values. |
4031
|
|
|
|
|
|
|
|
4032
|
|
|
|
|
|
|
END |
4033
|
|
|
|
|
|
|
|
4034
|
|
|
|
|
|
|
|
4035
|
|
|
|
|
|
|
$HELP{'xsh:new-element'}=[<<'END']; |
4036
|
|
|
|
|
|
|
usage: node-set xsh:new-element(string NAME,[string ATTR1-NAME1, |
4037
|
|
|
|
|
|
|
string ATTR-VALUE1, ...]) |
4038
|
|
|
|
|
|
|
|
4039
|
|
|
|
|
|
|
description: |
4040
|
|
|
|
|
|
|
Create a new element node with given 'NAME' and optionally |
4041
|
|
|
|
|
|
|
attributes with given names and values and return a node-set |
4042
|
|
|
|
|
|
|
containing the new node as its only member. |
4043
|
|
|
|
|
|
|
|
4044
|
|
|
|
|
|
|
END |
4045
|
|
|
|
|
|
|
|
4046
|
|
|
|
|
|
|
|
4047
|
|
|
|
|
|
|
$HELP{'xsh:new-element-ns'}=[<<'END']; |
4048
|
|
|
|
|
|
|
usage: node-set xsh:new-element-ns(string NAME,string NS,[string ATTR1-NAME1, |
4049
|
|
|
|
|
|
|
string ATTR-VALUE1, ...]) |
4050
|
|
|
|
|
|
|
|
4051
|
|
|
|
|
|
|
description: |
4052
|
|
|
|
|
|
|
Create a new element node with given 'NAME' and namespace-uri |
4053
|
|
|
|
|
|
|
'NS' and optionally attributes with given names and values and |
4054
|
|
|
|
|
|
|
return a node-set containing the new node as its only member. |
4055
|
|
|
|
|
|
|
|
4056
|
|
|
|
|
|
|
END |
4057
|
|
|
|
|
|
|
|
4058
|
|
|
|
|
|
|
|
4059
|
|
|
|
|
|
|
$HELP{'xsh:new-text'}=[<<'END']; |
4060
|
|
|
|
|
|
|
usage: node-set xsh:new-text(string DATA) |
4061
|
|
|
|
|
|
|
|
4062
|
|
|
|
|
|
|
description: |
4063
|
|
|
|
|
|
|
Create a new text node containing given 'DATA' and return a |
4064
|
|
|
|
|
|
|
node-set containing the new node as its only member. |
4065
|
|
|
|
|
|
|
|
4066
|
|
|
|
|
|
|
END |
4067
|
|
|
|
|
|
|
|
4068
|
|
|
|
|
|
|
|
4069
|
|
|
|
|
|
|
$HELP{'xsh:new-comment'}=[<<'END']; |
4070
|
|
|
|
|
|
|
usage: node-set xsh:new-comment(string DATA) |
4071
|
|
|
|
|
|
|
|
4072
|
|
|
|
|
|
|
description: |
4073
|
|
|
|
|
|
|
Create a new comment node containing given 'DATA' and return a |
4074
|
|
|
|
|
|
|
node-set containing the new node as its only member. |
4075
|
|
|
|
|
|
|
|
4076
|
|
|
|
|
|
|
END |
4077
|
|
|
|
|
|
|
|
4078
|
|
|
|
|
|
|
|
4079
|
|
|
|
|
|
|
$HELP{'xsh:new-pi'}=[<<'END']; |
4080
|
|
|
|
|
|
|
usage: node-set xsh:new-pi(string NAME, [string DATA]) |
4081
|
|
|
|
|
|
|
|
4082
|
|
|
|
|
|
|
description: |
4083
|
|
|
|
|
|
|
Create a new processing instruction node node with given |
4084
|
|
|
|
|
|
|
'NAME' and (optionally) given 'DATA' and return a node-set |
4085
|
|
|
|
|
|
|
containing the new node as its only member. |
4086
|
|
|
|
|
|
|
|
4087
|
|
|
|
|
|
|
END |
4088
|
|
|
|
|
|
|
|
4089
|
|
|
|
|
|
|
|
4090
|
|
|
|
|
|
|
$HELP{'xsh:new-cdata'}=[<<'END']; |
4091
|
|
|
|
|
|
|
usage: node-set xsh:new-cdata(string DATA) |
4092
|
|
|
|
|
|
|
|
4093
|
|
|
|
|
|
|
description: |
4094
|
|
|
|
|
|
|
Create a new cdata section node node filled with given 'DATA' |
4095
|
|
|
|
|
|
|
and return a node-set containing the new node as its only |
4096
|
|
|
|
|
|
|
member. |
4097
|
|
|
|
|
|
|
|
4098
|
|
|
|
|
|
|
END |
4099
|
|
|
|
|
|
|
|
4100
|
|
|
|
|
|
|
|
4101
|
|
|
|
|
|
|
$HELP{'xsh:new-chunk'}=[<<'END']; |
4102
|
|
|
|
|
|
|
usage: node-set xsh:new-chunk(string XML) |
4103
|
|
|
|
|
|
|
|
4104
|
|
|
|
|
|
|
description: |
4105
|
|
|
|
|
|
|
This is just an alias for [xsh:parse]. It parses given piece |
4106
|
|
|
|
|
|
|
of XML and returns a node-set consisting of the top-level |
4107
|
|
|
|
|
|
|
element within the parsed tree. |
4108
|
|
|
|
|
|
|
|
4109
|
|
|
|
|
|
|
END |
4110
|
|
|
|
|
|
|
|
4111
|
|
|
|
|
|
|
|
4112
|
|
|
|
|
|
|
$HELP{'xsh:map'}=[<<'END']; |
4113
|
|
|
|
|
|
|
usage: node-set xsh:map(node-set NODE, string XPATH) |
4114
|
|
|
|
|
|
|
|
4115
|
|
|
|
|
|
|
description: |
4116
|
|
|
|
|
|
|
This function is very similar to EXSLT 'dynamic:map' function. |
4117
|
|
|
|
|
|
|
The description below is almost literally taken from the EXSLT |
4118
|
|
|
|
|
|
|
specification. |
4119
|
|
|
|
|
|
|
|
4120
|
|
|
|
|
|
|
The 'xsh:map' function evaluates the expression passed as the |
4121
|
|
|
|
|
|
|
second argument for each of the nodes passed as the first |
4122
|
|
|
|
|
|
|
argument, and returns a node-set of those values. |
4123
|
|
|
|
|
|
|
|
4124
|
|
|
|
|
|
|
The expressions are evaluated relative to the nodes passed as |
4125
|
|
|
|
|
|
|
the first argument. In other words, the value for each node is |
4126
|
|
|
|
|
|
|
calculated by evaluating the XPath expression with all context |
4127
|
|
|
|
|
|
|
information being the same as that for the call to the |
4128
|
|
|
|
|
|
|
'xsh:map' function itself, except for the following: |
4129
|
|
|
|
|
|
|
|
4130
|
|
|
|
|
|
|
1) the context node is the node whose value is being |
4131
|
|
|
|
|
|
|
calculated, 2) the context position is the position of the |
4132
|
|
|
|
|
|
|
node within the node set passed as the first argument to the |
4133
|
|
|
|
|
|
|
'xsh:map' function, arranged in document order, and 3) the |
4134
|
|
|
|
|
|
|
context size is the number of nodes passed as the first |
4135
|
|
|
|
|
|
|
argument to the dyn:map function. |
4136
|
|
|
|
|
|
|
|
4137
|
|
|
|
|
|
|
If the expression string passed as the second argument is an |
4138
|
|
|
|
|
|
|
invalid XPath expression (including an empty string), this |
4139
|
|
|
|
|
|
|
function returns an empty node set. |
4140
|
|
|
|
|
|
|
|
4141
|
|
|
|
|
|
|
If 'XPATH' evaluates as a node set, the 'xsh:map' function |
4142
|
|
|
|
|
|
|
returns the union of the node sets returned by evaluating the |
4143
|
|
|
|
|
|
|
expression for each of the nodes in the first argument. Note |
4144
|
|
|
|
|
|
|
that this may mean that the node set resulting from the call |
4145
|
|
|
|
|
|
|
to the 'xsh:map' function contains a different number of nodes |
4146
|
|
|
|
|
|
|
from the number in the node set passed as the first argument |
4147
|
|
|
|
|
|
|
to the function. |
4148
|
|
|
|
|
|
|
|
4149
|
|
|
|
|
|
|
If 'XPATH' evaluates as a number, the 'xsh:map' function |
4150
|
|
|
|
|
|
|
returns a node set containing one 'xsh:number' element |
4151
|
|
|
|
|
|
|
(namespace 'http://xsh.sourceforge.net/xsh/') for each node in |
4152
|
|
|
|
|
|
|
the node set passed as the first argument to the dyn:map |
4153
|
|
|
|
|
|
|
function, in document order. The string value of each |
4154
|
|
|
|
|
|
|
'xsh:number' element is the same as the result of converting |
4155
|
|
|
|
|
|
|
the number resulting from evaluating the expression to a |
4156
|
|
|
|
|
|
|
string as with the number function, with the exception that |
4157
|
|
|
|
|
|
|
Infinity results in an 'xsh:number' holding the highest number |
4158
|
|
|
|
|
|
|
the implementation can store, and -Infinity results in an |
4159
|
|
|
|
|
|
|
'xsh:number' holding the lowest number the implementation can |
4160
|
|
|
|
|
|
|
store. |
4161
|
|
|
|
|
|
|
|
4162
|
|
|
|
|
|
|
If 'XPATH' evaluates as a boolean, the 'xsh:map' function |
4163
|
|
|
|
|
|
|
returns a node set containing one 'xsh:boolean' element |
4164
|
|
|
|
|
|
|
(namespace 'http://xsh.sourceforge.net/xsh/') for each node in |
4165
|
|
|
|
|
|
|
the node set passed as the first argument to the 'xsh:map' |
4166
|
|
|
|
|
|
|
function, in document order. The string value of each |
4167
|
|
|
|
|
|
|
'xsh:boolean' element is 'true' if the expression evaluates as |
4168
|
|
|
|
|
|
|
true for the node, and is empty if the expression evaluates as |
4169
|
|
|
|
|
|
|
false. |
4170
|
|
|
|
|
|
|
|
4171
|
|
|
|
|
|
|
Otherwise, the 'xsh:map' function returns a node set |
4172
|
|
|
|
|
|
|
containing one 'xsh:string' element (namespace |
4173
|
|
|
|
|
|
|
'http://xsh.sourceforge.net/xsh/') for each node in the node |
4174
|
|
|
|
|
|
|
set passed as the first argument to the 'xsh:map' function, in |
4175
|
|
|
|
|
|
|
document order. The string value of each 'xsh:string' element |
4176
|
|
|
|
|
|
|
is the same as the result of converting the result of |
4177
|
|
|
|
|
|
|
evaluating the expression for the relevant node to a string as |
4178
|
|
|
|
|
|
|
with the string function. |
4179
|
|
|
|
|
|
|
|
4180
|
|
|
|
|
|
|
see also: xsh:evaluate |
4181
|
|
|
|
|
|
|
|
4182
|
|
|
|
|
|
|
END |
4183
|
|
|
|
|
|
|
|
4184
|
|
|
|
|
|
|
|
4185
|
|
|
|
|
|
|
$HELP{'xsh:evaluate'}=[<<'END']; |
4186
|
|
|
|
|
|
|
usage: node-set xsh:evaluate(string XPATH) |
4187
|
|
|
|
|
|
|
|
4188
|
|
|
|
|
|
|
description: |
4189
|
|
|
|
|
|
|
This function is very similar to EXSLT 'dynamic:evaluate' |
4190
|
|
|
|
|
|
|
function. The description below is almost literally taken from |
4191
|
|
|
|
|
|
|
the EXSLT specification. |
4192
|
|
|
|
|
|
|
|
4193
|
|
|
|
|
|
|
The 'xsh:evaluate' function evaluates a string as an XPath |
4194
|
|
|
|
|
|
|
expression and returns the resulting value, which might be a |
4195
|
|
|
|
|
|
|
boolean, number, string, node set, result tree fragment or |
4196
|
|
|
|
|
|
|
external object. The sole argument is the string to be |
4197
|
|
|
|
|
|
|
evaluated. |
4198
|
|
|
|
|
|
|
|
4199
|
|
|
|
|
|
|
The string is always evaluated exactly as if it had been |
4200
|
|
|
|
|
|
|
literally included in place of the call to the 'xsh:evaluate' |
4201
|
|
|
|
|
|
|
function. |
4202
|
|
|
|
|
|
|
|
4203
|
|
|
|
|
|
|
In other words, the context information used when evaluating |
4204
|
|
|
|
|
|
|
the XPath expression passed as the argument to the |
4205
|
|
|
|
|
|
|
'xsh:evaluate' function is exactly the same as the context |
4206
|
|
|
|
|
|
|
information used when evaluating the 'xsh:evaluate' function. |
4207
|
|
|
|
|
|
|
This context information includes: |
4208
|
|
|
|
|
|
|
|
4209
|
|
|
|
|
|
|
1. the context node, such that paths are evaluated relative |
4210
|
|
|
|
|
|
|
to the context node at the point where the 'xsh:evaluate' |
4211
|
|
|
|
|
|
|
function is called |
4212
|
|
|
|
|
|
|
|
4213
|
|
|
|
|
|
|
2. the context position, such that the expression can |
4214
|
|
|
|
|
|
|
contain calls to the position function |
4215
|
|
|
|
|
|
|
|
4216
|
|
|
|
|
|
|
3. the context size, such that the expression can contain |
4217
|
|
|
|
|
|
|
calls to the last function |
4218
|
|
|
|
|
|
|
|
4219
|
|
|
|
|
|
|
4. variable bindings, such that the expression can contain |
4220
|
|
|
|
|
|
|
variable references |
4221
|
|
|
|
|
|
|
|
4222
|
|
|
|
|
|
|
5. function library, such that the expression can contain |
4223
|
|
|
|
|
|
|
calls to extension functions |
4224
|
|
|
|
|
|
|
|
4225
|
|
|
|
|
|
|
6. namespace declarations, such that paths can contain |
4226
|
|
|
|
|
|
|
prefixes the current node, such that the expression can |
4227
|
|
|
|
|
|
|
contain calls to the current function |
4228
|
|
|
|
|
|
|
|
4229
|
|
|
|
|
|
|
If the expression string passed as the second argument is an |
4230
|
|
|
|
|
|
|
invalid XPath expression (including an empty string), this |
4231
|
|
|
|
|
|
|
function returns an empty node set. |
4232
|
|
|
|
|
|
|
|
4233
|
|
|
|
|
|
|
You should only use this function if the expression must be |
4234
|
|
|
|
|
|
|
constructed dynamically - otherwise it is much more efficient |
4235
|
|
|
|
|
|
|
to use the expression literally. For expressions that simply |
4236
|
|
|
|
|
|
|
give an element or attribute's name (to select a child element |
4237
|
|
|
|
|
|
|
or attribute), it is more efficient to use an expression in |
4238
|
|
|
|
|
|
|
the style: |
4239
|
|
|
|
|
|
|
|
4240
|
|
|
|
|
|
|
*[name() = $expression] |
4241
|
|
|
|
|
|
|
see also: xsh:map |
4242
|
|
|
|
|
|
|
|
4243
|
|
|
|
|
|
|
END |
4244
|
|
|
|
|
|
|
|
4245
|
|
|
|
|
|
|
|
4246
|
|
|
|
|
|
|
$HELP{'xsh:split'}=[<<'END']; |
4247
|
|
|
|
|
|
|
usage: node-set xsh:split(string PATTERN, string STRING) |
4248
|
|
|
|
|
|
|
|
4249
|
|
|
|
|
|
|
description: |
4250
|
|
|
|
|
|
|
This function provides direct access to the very powerful Perl |
4251
|
|
|
|
|
|
|
function 'split'. It splits 'STRING' to a list of fields. |
4252
|
|
|
|
|
|
|
'PATTERN' is a regular expression specifying strings |
4253
|
|
|
|
|
|
|
delimiting individual fields of 'STRING'. If 'PATTERN' is |
4254
|
|
|
|
|
|
|
empty, 'STRING' is split to individual characters. If the |
4255
|
|
|
|
|
|
|
regular expression in 'PATTERN' is enclosed in brackets, then |
4256
|
|
|
|
|
|
|
strings matching 'PATTERN' are also included in the resulting |
4257
|
|
|
|
|
|
|
list. |
4258
|
|
|
|
|
|
|
|
4259
|
|
|
|
|
|
|
The function returns a node-set consisting of newly created |
4260
|
|
|
|
|
|
|
'' elements containing individual strings of the |
4261
|
|
|
|
|
|
|
resulting list as their only text child nodes. |
4262
|
|
|
|
|
|
|
|
4263
|
|
|
|
|
|
|
END |
4264
|
|
|
|
|
|
|
|
4265
|
|
|
|
|
|
|
|
4266
|
|
|
|
|
|
|
$HELP{'xsh:times'}=[<<'END']; |
4267
|
|
|
|
|
|
|
usage: node-set xsh:times(string STRING, float COUNT) |
4268
|
|
|
|
|
|
|
|
4269
|
|
|
|
|
|
|
description: |
4270
|
|
|
|
|
|
|
This function returns a string resulting from concatenation of |
4271
|
|
|
|
|
|
|
'COUNT' copies of 'STRING'. 'COUNT' must be a non-negative |
4272
|
|
|
|
|
|
|
integer value. |
4273
|
|
|
|
|
|
|
|
4274
|
|
|
|
|
|
|
END |
4275
|
|
|
|
|
|
|
|
4276
|
|
|
|
|
|
|
|
4277
|
|
|
|
|
|
|
$HELP{'xsh:id2'}=[<<'END']; |
4278
|
|
|
|
|
|
|
usage: node-set xsh:id2(node-set DOC, string IDs) |
4279
|
|
|
|
|
|
|
|
4280
|
|
|
|
|
|
|
description: |
4281
|
|
|
|
|
|
|
This function is like XPath built-in 'id(IDs)' function, |
4282
|
|
|
|
|
|
|
except that it operates on the document specified in the first |
4283
|
|
|
|
|
|
|
argument. It returns a node-set consisting of nodes that |
4284
|
|
|
|
|
|
|
belong to the document DOC and whose ID belongs to the list of |
4285
|
|
|
|
|
|
|
space separated IDs specified in the second argument. |
4286
|
|
|
|
|
|
|
|
4287
|
|
|
|
|
|
|
END |
4288
|
|
|
|
|
|
|
|
4289
|
|
|
|
|
|
|
|
4290
|
|
|
|
|
|
|
$HELP{'xsh:lookup'}=[<<'END']; |
4291
|
|
|
|
|
|
|
usage: node-set xsh:lookup(string VARNAME, string KEY) |
4292
|
|
|
|
|
|
|
|
4293
|
|
|
|
|
|
|
description: |
4294
|
|
|
|
|
|
|
This function is similar to XSLT 'key()' function. It returns |
4295
|
|
|
|
|
|
|
a node-set stored in a hash VARNAME under the key KEY. The |
4296
|
|
|
|
|
|
|
VARNAME must be a name of a lexical or global XSH variable |
4297
|
|
|
|
|
|
|
containing a Perl hash reference. |
4298
|
|
|
|
|
|
|
|
4299
|
|
|
|
|
|
|
see also: hash |
4300
|
|
|
|
|
|
|
|
4301
|
|
|
|
|
|
|
END |
4302
|
|
|
|
|
|
|
|
4303
|
|
|
|
|
|
|
|
4304
|
|
|
|
|
|
|
$HELP{'xsh:document'}=[<<'END']; |
4305
|
|
|
|
|
|
|
usage: node-set xsh:document(string URL) |
4306
|
|
|
|
|
|
|
|
4307
|
|
|
|
|
|
|
description: |
4308
|
|
|
|
|
|
|
Looks up among the currently open document the one whose |
4309
|
|
|
|
|
|
|
filename is same as the given URL and returns the |
4310
|
|
|
|
|
|
|
corresponding document node. If no document's filename matches |
4311
|
|
|
|
|
|
|
exactly the given URL, then several heuristic matches are |
4312
|
|
|
|
|
|
|
tried: if the URI is a relative filename, it is tilde-expanded |
4313
|
|
|
|
|
|
|
and resolved (using the current working directory as a base) |
4314
|
|
|
|
|
|
|
and the lookup is restarted with the absolute filename; |
4315
|
|
|
|
|
|
|
finally, a lookup identifying filenames with URLs of the |
4316
|
|
|
|
|
|
|
file:// protocol is attempted. If the lookup fails completely, |
4317
|
|
|
|
|
|
|
an empty node set is returned. |
4318
|
|
|
|
|
|
|
|
4319
|
|
|
|
|
|
|
see also: hash |
4320
|
|
|
|
|
|
|
|
4321
|
|
|
|
|
|
|
END |
4322
|
|
|
|
|
|
|
|
4323
|
|
|
|
|
|
|
|
4324
|
|
|
|
|
|
|
$HELP{'xsh:documents'}=[<<'END']; |
4325
|
|
|
|
|
|
|
usage: node-set xsh:documents() |
4326
|
|
|
|
|
|
|
|
4327
|
|
|
|
|
|
|
description: |
4328
|
|
|
|
|
|
|
Returns a node-set consisting of the document nodes of all |
4329
|
|
|
|
|
|
|
currently open documents. |
4330
|
|
|
|
|
|
|
|
4331
|
|
|
|
|
|
|
see also: hash |
4332
|
|
|
|
|
|
|
|
4333
|
|
|
|
|
|
|
END |
4334
|
|
|
|
|
|
|
|
4335
|
|
|
|
|
|
|
|
4336
|
|
|
|
|
|
|
$HELP{'xsh:span'}=[<<'END']; |
4337
|
|
|
|
|
|
|
usage: node-set xsh:span(node-set START,node-set END) |
4338
|
|
|
|
|
|
|
|
4339
|
|
|
|
|
|
|
description: |
4340
|
|
|
|
|
|
|
Returns a node-set which forms a span of sibling nodes |
4341
|
|
|
|
|
|
|
starting at START node and ending at END node (only the first |
4342
|
|
|
|
|
|
|
node of each of the nodesets is used). It is an error if the |
4343
|
|
|
|
|
|
|
START node and END node are not siblings. |
4344
|
|
|
|
|
|
|
|
4345
|
|
|
|
|
|
|
END |
4346
|
|
|
|
|
|
|
|
4347
|
|
|
|
|
|
|
|
4348
|
|
|
|
|
|
|
$HELP{'xsh:context'}=[<<'END']; |
4349
|
|
|
|
|
|
|
usage: node-set xsh:context(node-set NODE, float BEFORE, float AFTER) |
4350
|
|
|
|
|
|
|
|
4351
|
|
|
|
|
|
|
description: |
4352
|
|
|
|
|
|
|
Returns a node-set of sibling nodes surrounding NODE. The span |
4353
|
|
|
|
|
|
|
consists of (up to) BEFORE-many nodes immediately preceding |
4354
|
|
|
|
|
|
|
NODE, the NODE itself, and (up to) AFTER-many nodes |
4355
|
|
|
|
|
|
|
immediately following NODE. If the AFTER is not given, AFTER |
4356
|
|
|
|
|
|
|
is set equal to BEFORE. |
4357
|
|
|
|
|
|
|
|
4358
|
|
|
|
|
|
|
END |
4359
|
|
|
|
|
|
|
|
4360
|
|
|
|
|
|
|
|
4361
|
|
|
|
|
|
|
$HELP{'call'}=[<<'END']; |
4362
|
|
|
|
|
|
|
usage: call [expression] [[expression] ...] |
4363
|
|
|
|
|
|
|
|
4364
|
|
|
|
|
|
|
description: |
4365
|
|
|
|
|
|
|
Call a subroutine whose name is computed by evaluating the |
4366
|
|
|
|
|
|
|
first argument [expression]. All other expressions are |
4367
|
|
|
|
|
|
|
evaluated too and the results are passed to the subroutine as |
4368
|
|
|
|
|
|
|
arguments. |
4369
|
|
|
|
|
|
|
|
4370
|
|
|
|
|
|
|
This command should only be used if the name of the subroutine |
4371
|
|
|
|
|
|
|
isn't known at the compile time. Otherwise it is recommended |
4372
|
|
|
|
|
|
|
to use a direct subroutine call of the form: |
4373
|
|
|
|
|
|
|
|
4374
|
|
|
|
|
|
|
subroutine-name [argument1 argument2 ...] |
4375
|
|
|
|
|
|
|
Example: |
4376
|
|
|
|
|
|
|
def a $arg { echo "A says" $arg } |
4377
|
|
|
|
|
|
|
def b $arg { echo "B says" $arg } |
4378
|
|
|
|
|
|
|
a "hallo!"; # call subroutine a |
4379
|
|
|
|
|
|
|
b "hallo!"; # call subroutine b |
4380
|
|
|
|
|
|
|
call { chr(ord("a")+rand(2)) } "surprise!"; # call a or b randomly |
4381
|
|
|
|
|
|
|
|
4382
|
|
|
|
|
|
|
see also: def return |
4383
|
|
|
|
|
|
|
|
4384
|
|
|
|
|
|
|
END |
4385
|
|
|
|
|
|
|
|
4386
|
|
|
|
|
|
|
|
4387
|
|
|
|
|
|
|
$HELP{'Documents'}=[<<'END']; |
4388
|
|
|
|
|
|
|
Files/Documents |
4389
|
|
|
|
|
|
|
--------------- |
4390
|
|
|
|
|
|
|
|
4391
|
|
|
|
|
|
|
XSH2 is designed as an environment for querying and manipulating XML and |
4392
|
|
|
|
|
|
|
HTML documents. Use [open] or [create] commands to load an XML or HTML |
4393
|
|
|
|
|
|
|
document from a local file, external URL (such as http:// or ftp://), |
4394
|
|
|
|
|
|
|
string or pipe. XSH2 can optionally validate the document during parse |
4395
|
|
|
|
|
|
|
process (see [validation] and [load-ext-dtd]). Parsed documents are |
4396
|
|
|
|
|
|
|
stored in memory as DOM trees, that can be [navigated] and [manipulated] |
4397
|
|
|
|
|
|
|
with XSH2 commands and XPath language, whose names and syntax make |
4398
|
|
|
|
|
|
|
working with the DOM tree a flavor of working in a UNIX filesystem. |
4399
|
|
|
|
|
|
|
|
4400
|
|
|
|
|
|
|
A parsed document is usually stored in a variable. XSH2 shares variables |
4401
|
|
|
|
|
|
|
with the XPath engine, so if e.g. '$doc' is a XSH2 variable holding a |
4402
|
|
|
|
|
|
|
document (or, more generally any node-set), then '$doc//section/title' is |
4403
|
|
|
|
|
|
|
an XPath expression selecting all 'title' subelements of all 'section' |
4404
|
|
|
|
|
|
|
elements within the (sub)tree of $doc. |
4405
|
|
|
|
|
|
|
|
4406
|
|
|
|
|
|
|
Although XSH2 is able to parse remote documents via 'http://' or |
4407
|
|
|
|
|
|
|
'ftp://', it is only able to save them locally. To upload a document to a |
4408
|
|
|
|
|
|
|
remote server (e.g. using FTP) or to store it into a database, use [save] |
4409
|
|
|
|
|
|
|
command with a '--pipe' parameter, in connection with an external program |
4410
|
|
|
|
|
|
|
able to store its standard input (XML) to the desired location. You can |
4411
|
|
|
|
|
|
|
also use similar parameter with [open] in order to parse documents from |
4412
|
|
|
|
|
|
|
standard output of some external program. |
4413
|
|
|
|
|
|
|
|
4414
|
|
|
|
|
|
|
Example: Store a XSH2 document on a remote machine using the Secure Shell |
4415
|
|
|
|
|
|
|
|
4416
|
|
|
|
|
|
|
xsh> save --pipe "ssh my.remote.org 'cat > test.xml'" $doc |
4417
|
|
|
|
|
|
|
|
4418
|
|
|
|
|
|
|
|
4419
|
|
|
|
|
|
|
Related help items: |
4420
|
|
|
|
|
|
|
backups, catalog, clone, close, create, documents, index, nobackups, |
4421
|
|
|
|
|
|
|
open, process-xinclude, save, set_filename, stream, |
4422
|
|
|
|
|
|
|
switch-to-new-documents |
4423
|
|
|
|
|
|
|
|
4424
|
|
|
|
|
|
|
END |
4425
|
|
|
|
|
|
|
|
4426
|
|
|
|
|
|
|
$HELP{'Navigation'}=[<<'END']; |
4427
|
|
|
|
|
|
|
Tree navigation |
4428
|
|
|
|
|
|
|
--------------- |
4429
|
|
|
|
|
|
|
|
4430
|
|
|
|
|
|
|
With XSH2, it is possible to browse a [document tree] (XML data |
4431
|
|
|
|
|
|
|
represented as a DOM-tree) as if it was a local filesystem, except that |
4432
|
|
|
|
|
|
|
[XPath] expressions are used instead of ordinary directory paths. |
4433
|
|
|
|
|
|
|
|
4434
|
|
|
|
|
|
|
To mimic the filesystem navigation as closely as possible, XSH2 contains |
4435
|
|
|
|
|
|
|
several commands named by analogy of UNIX filesystem commands, such as |
4436
|
|
|
|
|
|
|
[cd], [ls] and [pwd]. |
4437
|
|
|
|
|
|
|
|
4438
|
|
|
|
|
|
|
The current position in the document tree is called the current node. |
4439
|
|
|
|
|
|
|
Current node's XPath may be queried with [pwd] command. In the |
4440
|
|
|
|
|
|
|
interactive shell, current node is also displayed in the command line |
4441
|
|
|
|
|
|
|
prompt. (Since there may be multiple document trees open at the same |
4442
|
|
|
|
|
|
|
time, XSH2 tries to locate a variable holding the current document and |
4443
|
|
|
|
|
|
|
use it to fully qualify current node's XPath in the XSH2 prompt.) |
4444
|
|
|
|
|
|
|
Remember, that beside [cd] command, current node (and document) is also |
4445
|
|
|
|
|
|
|
silently changed by [open] command, [create] command and temporarily also |
4446
|
|
|
|
|
|
|
by the node-list variant of the [foreach] loop without a loop variable. |
4447
|
|
|
|
|
|
|
|
4448
|
|
|
|
|
|
|
XPath expressions are always evaluated in context of the current node. |
4449
|
|
|
|
|
|
|
Different documents can be accessed through variables: '$doc/foo[1]/bar'. |
4450
|
|
|
|
|
|
|
|
4451
|
|
|
|
|
|
|
Example: XSH2 shell |
4452
|
|
|
|
|
|
|
|
4453
|
|
|
|
|
|
|
$scratch:/> $docA := open "testA.xml" |
4454
|
|
|
|
|
|
|
$docA/> $docB := open "testB.xml" |
4455
|
|
|
|
|
|
|
$docB/> pwd |
4456
|
|
|
|
|
|
|
/ |
4457
|
|
|
|
|
|
|
$docB/> cd $docA/article/chapter[title='Conclusion'] |
4458
|
|
|
|
|
|
|
$docA/article/chapter[5]> pwd |
4459
|
|
|
|
|
|
|
/article/chapter[5] |
4460
|
|
|
|
|
|
|
$docA/article/chapter[5]> cd previous-sibling::chapter |
4461
|
|
|
|
|
|
|
$docA/article/chapter[4]> cd .. |
4462
|
|
|
|
|
|
|
$docA/article> cd $docB |
4463
|
|
|
|
|
|
|
$docB:/> ls |
4464
|
|
|
|
|
|
|
|
4465
|
|
|
|
|
|
|
... |
4466
|
|
|
|
|
|
|
|
4467
|
|
|
|
|
|
|
|
4468
|
|
|
|
|
|
|
Related help items: |
4469
|
|
|
|
|
|
|
canonical, cd, fold, locate, ls, pwd, register-function, unfold, |
4470
|
|
|
|
|
|
|
unregister-function |
4471
|
|
|
|
|
|
|
|
4472
|
|
|
|
|
|
|
END |
4473
|
|
|
|
|
|
|
|
4474
|
|
|
|
|
|
|
$HELP{'Manipulation'}=[<<'END']; |
4475
|
|
|
|
|
|
|
Tree modification |
4476
|
|
|
|
|
|
|
----------------- |
4477
|
|
|
|
|
|
|
|
4478
|
|
|
|
|
|
|
XSH2 not only provides ways to browse and inspect the DOM tree but also |
4479
|
|
|
|
|
|
|
many commands to modify its content by various operations, such as |
4480
|
|
|
|
|
|
|
copying, moving, and deleting its nodes as well as creating completely |
4481
|
|
|
|
|
|
|
new nodes or XML fragments and attaching them to it. It is quite easy to |
4482
|
|
|
|
|
|
|
learn these commands since their names or aliases mimic their well-known |
4483
|
|
|
|
|
|
|
filesystem analogies. On the other hand, many of these commands have two |
4484
|
|
|
|
|
|
|
versions one of which is prefixed with a letter "x". This "x" stands for |
4485
|
|
|
|
|
|
|
"cross", thus e.g. [xcopy] should be read as "cross copy". Let's explain |
4486
|
|
|
|
|
|
|
the difference on the example of [xcopy]. |
4487
|
|
|
|
|
|
|
|
4488
|
|
|
|
|
|
|
In a copy operation, you have to specify what nodes are to be copied and |
4489
|
|
|
|
|
|
|
where to, in other words, you have to specify the source and the target. |
4490
|
|
|
|
|
|
|
XSH2 is very much XPath-based so, XPath is used here to specify both of |
4491
|
|
|
|
|
|
|
them. However, there might be more than one node that satisfies an XPath |
4492
|
|
|
|
|
|
|
expression. So, the rule of thumb is that the "cross" variant of a |
4493
|
|
|
|
|
|
|
command places one and every of the source nodes to the location of one |
4494
|
|
|
|
|
|
|
and every destination node, while the plain variant works one-by-one, |
4495
|
|
|
|
|
|
|
placing the first source node to the first destination, the second source |
4496
|
|
|
|
|
|
|
node to the second destination, and so on (as long as there are both |
4497
|
|
|
|
|
|
|
source nodes and destinations left). |
4498
|
|
|
|
|
|
|
|
4499
|
|
|
|
|
|
|
Example: |
4500
|
|
|
|
|
|
|
$scratch/> $a := create ""; |
4501
|
|
|
|
|
|
|
$a/> $b := create ""; |
4502
|
|
|
|
|
|
|
$b/> xcopy $a//A replace $b//B; |
4503
|
|
|
|
|
|
|
$b/> copy $b//C before $a//A; |
4504
|
|
|
|
|
|
|
$b/> ls $a; |
4505
|
|
|
|
|
|
|
|
4506
|
|
|
|
|
|
|
|
4507
|
|
|
|
|
|
|
|
4508
|
|
|
|
|
|
|
$b/> ls $b; |
4509
|
|
|
|
|
|
|
|
4510
|
|
|
|
|
|
|
|
4511
|
|
|
|
|
|
|
|
4512
|
|
|
|
|
|
|
As already indicated by the example, another issue of tree modification |
4513
|
|
|
|
|
|
|
is the way in which the destination node determines the target location. |
4514
|
|
|
|
|
|
|
Should the source node be placed before, after, or somewhere among the |
4515
|
|
|
|
|
|
|
children of the resulting node? Or maybe, should it replace it |
4516
|
|
|
|
|
|
|
completely? This information has to be given in the [location] argument |
4517
|
|
|
|
|
|
|
that usually precedes the destination XPath. |
4518
|
|
|
|
|
|
|
|
4519
|
|
|
|
|
|
|
Now, what happens if source and destination nodes are of incompatible |
4520
|
|
|
|
|
|
|
types? XSH2 tries to avoid this by implicitly converting between node |
4521
|
|
|
|
|
|
|
types when necessary. For example, if a text, comment, and attribute node |
4522
|
|
|
|
|
|
|
is copied into, before or after an attribute node, the original value of |
4523
|
|
|
|
|
|
|
the attribute is replaced, prepended or appended respectively with the |
4524
|
|
|
|
|
|
|
textual content of the source node. Note however, that element nodes are |
4525
|
|
|
|
|
|
|
never converted into text, attribute or any other textual node. There are |
4526
|
|
|
|
|
|
|
many combinations here, so try yourself and see the results. |
4527
|
|
|
|
|
|
|
|
4528
|
|
|
|
|
|
|
You may even use some more sophisticated way to convert between node |
4529
|
|
|
|
|
|
|
types, as shown in the following example, where an element is first |
4530
|
|
|
|
|
|
|
commented out and than again uncommented. Note, that the particular |
4531
|
|
|
|
|
|
|
approach used for resurrecting the commented XML material works only for |
4532
|
|
|
|
|
|
|
well-balanced chunks of XML. |
4533
|
|
|
|
|
|
|
|
4534
|
|
|
|
|
|
|
Example: Using string variables to convert between different types of nodes |
4535
|
|
|
|
|
|
|
|
4536
|
|
|
|
|
|
|
$doc := create <
|
4537
|
|
|
|
|
|
|
|
4538
|
|
|
|
|
|
|
|
4539
|
|
|
|
|
|
|
|
4540
|
|
|
|
|
|
|
Intro |
4541
|
|
|
|
|
|
|
|
4542
|
|
|
|
|
|
|
|
4543
|
|
|
|
|
|
|
Rest |
4544
|
|
|
|
|
|
|
|
4545
|
|
|
|
|
|
|
|
4546
|
|
|
|
|
|
|
EOF |
4547
|
|
|
|
|
|
|
|
4548
|
|
|
|
|
|
|
# comment out the first chapter |
4549
|
|
|
|
|
|
|
ls //chapter[1] |> $chapter_xml; |
4550
|
|
|
|
|
|
|
insert comment $chapter_xml replace //chapter[1]; |
4551
|
|
|
|
|
|
|
ls / 0; |
4552
|
|
|
|
|
|
|
# OUTPUT: |
4553
|
|
|
|
|
|
|
|
4554
|
|
|
|
|
|
|
|
4555
|
|
|
|
|
|
|
|
4559
|
|
|
|
|
|
|
|
4560
|
|
|
|
|
|
|
Rest |
4561
|
|
|
|
|
|
|
|
4562
|
|
|
|
|
|
|
|
4563
|
|
|
|
|
|
|
|
4564
|
|
|
|
|
|
|
|
4565
|
|
|
|
|
|
|
# un-comment the chapter |
4566
|
|
|
|
|
|
|
$comment = string(//comment()[1]); |
4567
|
|
|
|
|
|
|
insert chunk $comment replace //comment()[1]; |
4568
|
|
|
|
|
|
|
ls / 0; |
4569
|
|
|
|
|
|
|
# OUTPUT: |
4570
|
|
|
|
|
|
|
|
4571
|
|
|
|
|
|
|
|
4572
|
|
|
|
|
|
|
|
4573
|
|
|
|
|
|
|
Intro |
4574
|
|
|
|
|
|
|
|
4575
|
|
|
|
|
|
|
|
4576
|
|
|
|
|
|
|
|
4577
|
|
|
|
|
|
|
Rest |
4578
|
|
|
|
|
|
|
|
4579
|
|
|
|
|
|
|
|
4580
|
|
|
|
|
|
|
|
4581
|
|
|
|
|
|
|
|
4582
|
|
|
|
|
|
|
Related help items: |
4583
|
|
|
|
|
|
|
change-ns-prefix, change-ns-uri, clone, copy, declare-ns, edit, |
4584
|
|
|
|
|
|
|
edit-string, hash, insert, map, move, normalize, process-xinclude, |
4585
|
|
|
|
|
|
|
remove, rename, set, set-dtd, set-enc, set-ns, set-standalone, sort, |
4586
|
|
|
|
|
|
|
strip-whitespace, wrap, wrap-span, xcopy, xinsert, xmove, xslt, xupdate |
4587
|
|
|
|
|
|
|
|
4588
|
|
|
|
|
|
|
END |
4589
|
|
|
|
|
|
|
|
4590
|
|
|
|
|
|
|
$HELP{'Flow'}=[<<'END']; |
4591
|
|
|
|
|
|
|
Flow control |
4592
|
|
|
|
|
|
|
------------ |
4593
|
|
|
|
|
|
|
|
4594
|
|
|
|
|
|
|
As almost every scripting language, XSH2 supports subroutines, various |
4595
|
|
|
|
|
|
|
conditional statements, loops and even exceptions. |
4596
|
|
|
|
|
|
|
|
4597
|
|
|
|
|
|
|
|
4598
|
|
|
|
|
|
|
Related help items: |
4599
|
|
|
|
|
|
|
call, def, do, eval, exit, foreach, if, ifinclude, include, iterate, |
4600
|
|
|
|
|
|
|
last, next, prev, redo, return, run-mode, stream, test-mode, throw, try, |
4601
|
|
|
|
|
|
|
undef, unless, while |
4602
|
|
|
|
|
|
|
|
4603
|
|
|
|
|
|
|
END |
4604
|
|
|
|
|
|
|
|
4605
|
|
|
|
|
|
|
$HELP{'Information'}=[<<'END']; |
4606
|
|
|
|
|
|
|
Retrieving more information |
4607
|
|
|
|
|
|
|
--------------------------- |
4608
|
|
|
|
|
|
|
|
4609
|
|
|
|
|
|
|
Beside the possibility to browse the DOM tree and list some parts of it |
4610
|
|
|
|
|
|
|
(as described in [Navigation]), XSH2 provides commands to obtain other |
4611
|
|
|
|
|
|
|
information related to open documents as well as the XSH2 interpreter |
4612
|
|
|
|
|
|
|
itself. These commands are listed bellow. |
4613
|
|
|
|
|
|
|
|
4614
|
|
|
|
|
|
|
|
4615
|
|
|
|
|
|
|
Related help items: |
4616
|
|
|
|
|
|
|
apropos, canonical, count, defs, doc-info, documents, dtd, enc, get, |
4617
|
|
|
|
|
|
|
help, lineno, locate, ls, namespaces, print, pwd, settings, validate, |
4618
|
|
|
|
|
|
|
variables, version |
4619
|
|
|
|
|
|
|
|
4620
|
|
|
|
|
|
|
END |
4621
|
|
|
|
|
|
|
|
4622
|
|
|
|
|
|
|
$HELP{'Namespaces'}=[<<'END']; |
4623
|
|
|
|
|
|
|
Namespaces in XML and XPath |
4624
|
|
|
|
|
|
|
--------------------------- |
4625
|
|
|
|
|
|
|
|
4626
|
|
|
|
|
|
|
Namespaces provide a simple method for qualifying element and attribute |
4627
|
|
|
|
|
|
|
names in XML documents. Namespaces are represented by a namespace URI |
4628
|
|
|
|
|
|
|
but, since the URI can be very long, element and attribute names are |
4629
|
|
|
|
|
|
|
associated with a namespace using a namespace prefix (see the W3C |
4630
|
|
|
|
|
|
|
recommendation for details). In an XML document, a prefix can be |
4631
|
|
|
|
|
|
|
associated with a namespace URI using a declaration which takes form of |
4632
|
|
|
|
|
|
|
special attribute of the form 'xmlns:prefix="namespace uri"' on an |
4633
|
|
|
|
|
|
|
element. The scope of the namespace declaration is then the subtree of |
4634
|
|
|
|
|
|
|
the element carrying the special 'xmlns:prefix' attribute (and includes |
4635
|
|
|
|
|
|
|
attributes of the element). Moreover, a default namespace can be declared |
4636
|
|
|
|
|
|
|
using just 'xmlns="namespace uri"'. In that case all unprefixed element |
4637
|
|
|
|
|
|
|
names in the scope of such a declaration belong to the namespace. An |
4638
|
|
|
|
|
|
|
unprefixed element which is not in scope of a default namespace |
4639
|
|
|
|
|
|
|
declaration does not belong to any namespace. It is recommended not to |
4640
|
|
|
|
|
|
|
combine namespaced elements and non-namespaced elements in a single |
4641
|
|
|
|
|
|
|
document. Note that regardless of default namespace declarations, |
4642
|
|
|
|
|
|
|
unprefixed attributes do not belong to any namespace (because they are |
4643
|
|
|
|
|
|
|
uniquely determined by their name and the namespace and name of the the |
4644
|
|
|
|
|
|
|
element which carries them). |
4645
|
|
|
|
|
|
|
|
4646
|
|
|
|
|
|
|
XSH2 tries to deal namespace declarations transparently (creating them if |
4647
|
|
|
|
|
|
|
necessary when nodes are copied between different documents or scopes of |
4648
|
|
|
|
|
|
|
namespace declarations). Most commands which create new elements or |
4649
|
|
|
|
|
|
|
attributes provide means to indicate a namespace. In addition, XSH2 |
4650
|
|
|
|
|
|
|
provides commands [declare-ns], [set-ns], [change-ns-uri], and |
4651
|
|
|
|
|
|
|
[change-ns-prefix] to directly manipulate XML namespace declarations on |
4652
|
|
|
|
|
|
|
the current node. |
4653
|
|
|
|
|
|
|
|
4654
|
|
|
|
|
|
|
Since XSH2 is heavily XPath-based, it is important to remember that XPath |
4655
|
|
|
|
|
|
|
1.0 maps prefixes to namespaces independently of the declarations in the |
4656
|
|
|
|
|
|
|
current document. The mapping is instead provided via so called XPath |
4657
|
|
|
|
|
|
|
context. Namespaces can be tested in XPath either using the built-in |
4658
|
|
|
|
|
|
|
'namespace-uri()' function, but it is more convenient to use namespace |
4659
|
|
|
|
|
|
|
prefixes associated with namespace URIs in the XPath context. This |
4660
|
|
|
|
|
|
|
association is independent of the documents to which the XPath expression |
4661
|
|
|
|
|
|
|
is applied and can be established using the command [register-namespace]. |
4662
|
|
|
|
|
|
|
Additional, XSH2 automatically propagates the namespace association in |
4663
|
|
|
|
|
|
|
the scope of the current node to the XPath context, so that per-document |
4664
|
|
|
|
|
|
|
prefixes in the current scope can also be used. |
4665
|
|
|
|
|
|
|
|
4666
|
|
|
|
|
|
|
IMPORTANT: XPath 1.0 has no concept of a default namespace. Unprefixed |
4667
|
|
|
|
|
|
|
names in XPath only match names which have no namespace. So, if the |
4668
|
|
|
|
|
|
|
document uses a default namespace, it is required to associate a |
4669
|
|
|
|
|
|
|
non-empty prefix with the default namespace via [register-namespace] and |
4670
|
|
|
|
|
|
|
add that prefix to names in XPath expressions intended to match nodes in |
4671
|
|
|
|
|
|
|
the default namespace. |
4672
|
|
|
|
|
|
|
|
4673
|
|
|
|
|
|
|
Example: Manipulating nodes in XHTML documents |
4674
|
|
|
|
|
|
|
|
4675
|
|
|
|
|
|
|
open "index.xhtml"; |
4676
|
|
|
|
|
|
|
$xhtmlns = "http://www.w3.org/1999/xhtml"; |
4677
|
|
|
|
|
|
|
register-namespace x $xhtmlns; |
4678
|
|
|
|
|
|
|
wrap --namespace $xhtmlns '' //x:a[@href]; |
4679
|
|
|
|
|
|
|
# or |
4680
|
|
|
|
|
|
|
wrap '' //x:a[@href]; |
4681
|
|
|
|
|
|
|
|
4682
|
|
|
|
|
|
|
In the preceding example we associate the (typically default) namespace |
4683
|
|
|
|
|
|
|
of XHTML documents with the prefix 'x'. We than use this prefix to match |
4684
|
|
|
|
|
|
|
all links ('a' elements) in the document. Note that we do not write |
4685
|
|
|
|
|
|
|
'@x:href' to match the '@href' attribute because unprefixed attributes do |
4686
|
|
|
|
|
|
|
not belong to the default namespace. The [wrap] command is used to create |
4687
|
|
|
|
|
|
|
new containing elements for the nodes matched by the XPath expression. We |
4688
|
|
|
|
|
|
|
may either specify the namespace of the containing element explicitly, |
4689
|
|
|
|
|
|
|
using '--namespace' option, or implicitly, by using a prefix associated |
4690
|
|
|
|
|
|
|
with the namespace in the XPath context. In the latter case, XSH2 chooses |
4691
|
|
|
|
|
|
|
a suitable prefix declared for the namespace in the document scope (in |
4692
|
|
|
|
|
|
|
this case the default, i.e. no, prefix), adding a new namespace |
4693
|
|
|
|
|
|
|
declaration if necessary. |
4694
|
|
|
|
|
|
|
|
4695
|
|
|
|
|
|
|
|
4696
|
|
|
|
|
|
|
Related help items: |
4697
|
|
|
|
|
|
|
change-ns-prefix, change-ns-uri, declare-ns, namespaces, |
4698
|
|
|
|
|
|
|
register-namespace, register-xhtml-namespace, register-xsh-namespace, |
4699
|
|
|
|
|
|
|
set-ns, unregister-namespace |
4700
|
|
|
|
|
|
|
|
4701
|
|
|
|
|
|
|
END |
4702
|
|
|
|
|
|
|
|
4703
|
|
|
|
|
|
|
$HELP{'Argtypes'}=[<<'END']; |
4704
|
|
|
|
|
|
|
Argument Types |
4705
|
|
|
|
|
|
|
-------------- |
4706
|
|
|
|
|
|
|
|
4707
|
|
|
|
|
|
|
XSH2 commands accept arguments of various types, usually expressed as |
4708
|
|
|
|
|
|
|
Perl or XPath [expression]s. Unlike in most languages, individual XSH2 |
4709
|
|
|
|
|
|
|
commands may evaluate the same expression differently, usually to enforce |
4710
|
|
|
|
|
|
|
a result of a certain type (such as a node-list, a string, a number, a |
4711
|
|
|
|
|
|
|
filename, a node name, etc.). See [expression] and individual argument |
4712
|
|
|
|
|
|
|
types for more information. |
4713
|
|
|
|
|
|
|
|
4714
|
|
|
|
|
|
|
END |
4715
|
|
|
|
|
|
|
|
4716
|
|
|
|
|
|
|
$HELP{'Variables'}=[<<'END']; |
4717
|
|
|
|
|
|
|
Variables |
4718
|
|
|
|
|
|
|
--------- |
4719
|
|
|
|
|
|
|
|
4720
|
|
|
|
|
|
|
In XSH2, like in Perl and XPath, [variable names] are are prefixed with a |
4721
|
|
|
|
|
|
|
dollar sign ($). Variables can contain arbitrary Perl Scalar (string, |
4722
|
|
|
|
|
|
|
number, array reference, hash reference or an object reference). XPath |
4723
|
|
|
|
|
|
|
objects are transparently mapped to Perl objects via XML::LibXML objects. |
4724
|
|
|
|
|
|
|
Values can be assigned to variables either by simple [assignments] of the |
4725
|
|
|
|
|
|
|
form '$variable = [expression]', where the right hand side is an |
4726
|
|
|
|
|
|
|
expression, or by command [assignments] of the form '$variable := |
4727
|
|
|
|
|
|
|
[command]', where the right hand side is a XSH2 command, or by capturing |
4728
|
|
|
|
|
|
|
the output of some command with a variable redirection of the following |
4729
|
|
|
|
|
|
|
form: |
4730
|
|
|
|
|
|
|
|
4731
|
|
|
|
|
|
|
command |> $variable; |
4732
|
|
|
|
|
|
|
XSH2 expressions are evaluated either by XPath engine or by Perl (the |
4733
|
|
|
|
|
|
|
latter only happens if the entire expression is enclosed with braces |
4734
|
|
|
|
|
|
|
'{...}'), and both Perl and XPath can access all XSH2 variables |
4735
|
|
|
|
|
|
|
transparently (Perl expressions may even assign to them). |
4736
|
|
|
|
|
|
|
|
4737
|
|
|
|
|
|
|
A simple simple expression consisting of a variable name (e.g. |
4738
|
|
|
|
|
|
|
'$variable') is always evaluated by the XPath engine and the result is |
4739
|
|
|
|
|
|
|
the content of the variable as it appears to the XPath data model. Since |
4740
|
|
|
|
|
|
|
in XPath object cannot be void (undefined), XPath engine complains, if |
4741
|
|
|
|
|
|
|
the value of the variable is undefined. On the other hand, expressions |
4742
|
|
|
|
|
|
|
like '{$variable}' are evaluated by Perl, which results in the value of |
4743
|
|
|
|
|
|
|
the variable as seen by Perl. |
4744
|
|
|
|
|
|
|
|
4745
|
|
|
|
|
|
|
Variables can also be used as macros for complicated XPath expressions. |
4746
|
|
|
|
|
|
|
Any occurrence of a substring of the form '${variable}' in an XPath |
4747
|
|
|
|
|
|
|
expression is interpolated to the value of '$variable' (if '$variable' |
4748
|
|
|
|
|
|
|
contains an object rather than a string or number, then the object is |
4749
|
|
|
|
|
|
|
cast to string first) before the entire expression is evaluated. So, for |
4750
|
|
|
|
|
|
|
example, if '${variable}' contains string "'chapter[title]'" (without the |
4751
|
|
|
|
|
|
|
quotes), then the XPath expression '//sect1/${variable}/para' |
4752
|
|
|
|
|
|
|
interpolates to '//sect1/chapter[title]/para' prior to evaluation. |
4753
|
|
|
|
|
|
|
|
4754
|
|
|
|
|
|
|
To display the current value of a variable, use either [print] or (in |
4755
|
|
|
|
|
|
|
case of a global variables - the distinction is discussed below) the |
4756
|
|
|
|
|
|
|
command [variables]: |
4757
|
|
|
|
|
|
|
|
4758
|
|
|
|
|
|
|
Example: |
4759
|
|
|
|
|
|
|
xsh> $b="my_document"; |
4760
|
|
|
|
|
|
|
xsh> $file="${b}s.xml"; |
4761
|
|
|
|
|
|
|
xsh> $f := open $file; |
4762
|
|
|
|
|
|
|
xsh> ls //$b[count(descendant::para)>10] |
4763
|
|
|
|
|
|
|
xsh> print $b |
4764
|
|
|
|
|
|
|
my_document |
4765
|
|
|
|
|
|
|
xsh> variables |
4766
|
|
|
|
|
|
|
... |
4767
|
|
|
|
|
|
|
$b='my_document'; |
4768
|
|
|
|
|
|
|
... |
4769
|
|
|
|
|
|
|
$file='my_documents.xml'; |
4770
|
|
|
|
|
|
|
... |
4771
|
|
|
|
|
|
|
|
4772
|
|
|
|
|
|
|
Variables can also serve as containers for documents and can be used to |
4773
|
|
|
|
|
|
|
store lists of nodes that result from evaluating an XPath expression |
4774
|
|
|
|
|
|
|
(a.k.a. XPath node-sets). This is especially useful when a sequence of |
4775
|
|
|
|
|
|
|
commands is to be performed on some fixed set of nodes and repetitive |
4776
|
|
|
|
|
|
|
evaluation of the same XPath expression would be lengthy. XPath node-sets |
4777
|
|
|
|
|
|
|
are represented by 'XML::LibXML::NodeList' Perl objects (which is simply |
4778
|
|
|
|
|
|
|
a array reference blessed to the above class, which provides some simple |
4779
|
|
|
|
|
|
|
operator overloading). In XPath, by a node-set by definition can only |
4780
|
|
|
|
|
|
|
contain a single copy of each node and the nodes within a node-set are |
4781
|
|
|
|
|
|
|
processed in the same order as they appear in the XML document. Having |
4782
|
|
|
|
|
|
|
XPath node-sets represented by a list gives us the advantage of having |
4783
|
|
|
|
|
|
|
the possibility to process the list in a different order than the one |
4784
|
|
|
|
|
|
|
implied by the document (which is what happens if a variable containing a |
4785
|
|
|
|
|
|
|
node-list is evaluated by Perl rather than XPath), see an example below. |
4786
|
|
|
|
|
|
|
|
4787
|
|
|
|
|
|
|
Example: |
4788
|
|
|
|
|
|
|
xsh> $creatures = //creature[@status='alive'] |
4789
|
|
|
|
|
|
|
# process creatures in the document order: |
4790
|
|
|
|
|
|
|
xsh> foreach $creature print @name; |
4791
|
|
|
|
|
|
|
# process creatures in the reverse document order: |
4792
|
|
|
|
|
|
|
xsh> foreach { reverse @$creature } print @name; |
4793
|
|
|
|
|
|
|
# append some more nodes to a node-list (using a variant of |
4794
|
|
|
|
|
|
|
# a simple assignment) |
4795
|
|
|
|
|
|
|
xsh> $creatures += //creature[@status='dead']; |
4796
|
|
|
|
|
|
|
# again, we can process creatures in order implied by the document: |
4797
|
|
|
|
|
|
|
xsh> foreach $creature print @name; |
4798
|
|
|
|
|
|
|
# but we can also process first living and then dead creatures, |
4799
|
|
|
|
|
|
|
# since this is how they are listed in $creature |
4800
|
|
|
|
|
|
|
xsh> foreach {$creature} print @name; |
4801
|
|
|
|
|
|
|
# same as the above is |
4802
|
|
|
|
|
|
|
xsh> foreach {@$creature} print @name; |
4803
|
|
|
|
|
|
|
|
4804
|
|
|
|
|
|
|
XSH2 variables are either globally or lexically scoped. Global variables |
4805
|
|
|
|
|
|
|
need not to be declared (they can be directly assigned to), whereas |
4806
|
|
|
|
|
|
|
lexical variables must be declared using the command [my]. Global |
4807
|
|
|
|
|
|
|
variable assignment may also be made temporal for the enclosing block, |
4808
|
|
|
|
|
|
|
using [local]. |
4809
|
|
|
|
|
|
|
|
4810
|
|
|
|
|
|
|
Example: |
4811
|
|
|
|
|
|
|
$var1 = "foo"; # a global variable requires no declaration |
4812
|
|
|
|
|
|
|
local $var1 $var2 $var3; # localizes global variables |
4813
|
|
|
|
|
|
|
$var1 = "bar"; # assignment to a localized variable is temporary |
4814
|
|
|
|
|
|
|
local $var4 = "foo"; # localized assignment |
4815
|
|
|
|
|
|
|
my $var1 $var $var3; # declares lexical variables |
4816
|
|
|
|
|
|
|
my $var1 = "foo"; # lexical variable declaration with assignment |
4817
|
|
|
|
|
|
|
|
4818
|
|
|
|
|
|
|
Lexical variables are only defined in the scope of current block or |
4819
|
|
|
|
|
|
|
subroutine. There is no way to refer to a lexical variable form outside |
4820
|
|
|
|
|
|
|
of the block it was declared in, nor from within a nested subroutine |
4821
|
|
|
|
|
|
|
call. Of course, lexical variables can be referred to from nested blocks |
4822
|
|
|
|
|
|
|
or Perl expressions (where they behave just like Perl's lexical |
4823
|
|
|
|
|
|
|
variables). |
4824
|
|
|
|
|
|
|
|
4825
|
|
|
|
|
|
|
On the other hand, global or localized XSH2 variables are just Perl |
4826
|
|
|
|
|
|
|
Scalar variables belonging to the 'XML::XSH2::Map' namespace, which is |
4827
|
|
|
|
|
|
|
also the default namespace for any Perl code evaluated from XSH2 (so |
4828
|
|
|
|
|
|
|
there's no need to use this prefix explicitly in Perl expressions, unless |
4829
|
|
|
|
|
|
|
of course there is a lexical variable in the current scope with the |
4830
|
|
|
|
|
|
|
same). |
4831
|
|
|
|
|
|
|
|
4832
|
|
|
|
|
|
|
Localizing a variable using the 'local' keyword makes all assignments to |
4833
|
|
|
|
|
|
|
it occurring in the enclosing block temporary. The variable itself |
4834
|
|
|
|
|
|
|
remains global, only its original value is restored at the end of the |
4835
|
|
|
|
|
|
|
block that localized it. |
4836
|
|
|
|
|
|
|
|
4837
|
|
|
|
|
|
|
In all above cases, it is possible to arbitrarily intermix XSH2 and Perl |
4838
|
|
|
|
|
|
|
assignments: |
4839
|
|
|
|
|
|
|
|
4840
|
|
|
|
|
|
|
Example: |
4841
|
|
|
|
|
|
|
xsh> ls //chapter[1]/title |
4842
|
|
|
|
|
|
|
Introduction |
4843
|
|
|
|
|
|
|
xsh> $a=string(//chapter[1]/title) |
4844
|
|
|
|
|
|
|
xsh> perl { $b="CHAPTER 1: ".uc($a); } |
4845
|
|
|
|
|
|
|
xsh> print $b |
4846
|
|
|
|
|
|
|
CHAPTER 1: INTRODUCTION |
4847
|
|
|
|
|
|
|
|
4848
|
|
|
|
|
|
|
Although all XSH2 variables are in fact Perl Scalars, it is still |
4849
|
|
|
|
|
|
|
possible to store Perl Array or Hash value to a XSH2 variable via |
4850
|
|
|
|
|
|
|
reference. The following example demonstrates using Perl Hashes to |
4851
|
|
|
|
|
|
|
collect and print some simple racial statistics about the population of |
4852
|
|
|
|
|
|
|
Middle-Earth: |
4853
|
|
|
|
|
|
|
|
4854
|
|
|
|
|
|
|
Example: |
4855
|
|
|
|
|
|
|
my $races; |
4856
|
|
|
|
|
|
|
foreach a:/middle-earth/creature { |
4857
|
|
|
|
|
|
|
my $race=string(@race); |
4858
|
|
|
|
|
|
|
perl { $races->{$race}++ }; |
4859
|
|
|
|
|
|
|
} |
4860
|
|
|
|
|
|
|
print "Middle-Earth Population (race/number of creatures)" |
4861
|
|
|
|
|
|
|
print { map "$_/$races->{$_}\n" keys(%$races); }; |
4862
|
|
|
|
|
|
|
|
4863
|
|
|
|
|
|
|
|
4864
|
|
|
|
|
|
|
Related help items: |
4865
|
|
|
|
|
|
|
assign, local |
4866
|
|
|
|
|
|
|
|
4867
|
|
|
|
|
|
|
END |
4868
|
|
|
|
|
|
|
|
4869
|
|
|
|
|
|
|
$HELP{'Redirection'}=[<<'END']; |
4870
|
|
|
|
|
|
|
Command output redirection |
4871
|
|
|
|
|
|
|
-------------------------- |
4872
|
|
|
|
|
|
|
|
4873
|
|
|
|
|
|
|
WARNING: XSH2 redirection syntax is not yet finished. It is currently the |
4874
|
|
|
|
|
|
|
same as in XSH1 but this may be changed in the future releases. |
4875
|
|
|
|
|
|
|
|
4876
|
|
|
|
|
|
|
Output redirection can be used to pipe output of some XSH [command] to |
4877
|
|
|
|
|
|
|
some external program, or to capture it to a variable. Redirection of |
4878
|
|
|
|
|
|
|
output of more than one XSH command can be achieved using the [do] |
4879
|
|
|
|
|
|
|
command. |
4880
|
|
|
|
|
|
|
|
4881
|
|
|
|
|
|
|
Redirect output to an external program |
4882
|
|
|
|
|
|
|
-------------------------------------- |
4883
|
|
|
|
|
|
|
|
4884
|
|
|
|
|
|
|
The syntax for redirecting the output of a XSH command to an external |
4885
|
|
|
|
|
|
|
program, is 'xsh-command | shell-command ;', where 'xsh-command' is any |
4886
|
|
|
|
|
|
|
XSH2 command and 'shell-command' is any command (or code) recognized by |
4887
|
|
|
|
|
|
|
the default shell interpreter of the operating system (i.e. on UNIX |
4888
|
|
|
|
|
|
|
systems by '/bin/sh' or '/bin/csh', on Windows systems by 'cmd'). The |
4889
|
|
|
|
|
|
|
shell command may contain further redirections (as supported by the |
4890
|
|
|
|
|
|
|
system shell interpreter), but should not contain semicolons, except |
4891
|
|
|
|
|
|
|
when the whole shell command is enclosed in brackets. |
4892
|
|
|
|
|
|
|
|
4893
|
|
|
|
|
|
|
Example: Use well-known UNIX commands to filter XPath-based XML listing |
4894
|
|
|
|
|
|
|
from a document and count the results |
4895
|
|
|
|
|
|
|
|
4896
|
|
|
|
|
|
|
xsh> ls //something/* | grep foo | wc |
4897
|
|
|
|
|
|
|
|
4898
|
|
|
|
|
|
|
Capture output to a variable |
4899
|
|
|
|
|
|
|
---------------------------- |
4900
|
|
|
|
|
|
|
|
4901
|
|
|
|
|
|
|
The syntax for capturing the output of an XSH command to a variable is |
4902
|
|
|
|
|
|
|
'xsh-command |> $variable', where 'xsh-command' is any XSH [command] |
4903
|
|
|
|
|
|
|
and '$variable' is any valid name for a [variable]. |
4904
|
|
|
|
|
|
|
|
4905
|
|
|
|
|
|
|
Example: Store the number of all words in a variable named count. |
4906
|
|
|
|
|
|
|
|
4907
|
|
|
|
|
|
|
xsh> count //words |> $count |
4908
|
|
|
|
|
|
|
|
4909
|
|
|
|
|
|
|
END |
4910
|
|
|
|
|
|
|
|
4911
|
|
|
|
|
|
|
$HELP{'Configuration'}=[<<'END']; |
4912
|
|
|
|
|
|
|
Global settings |
4913
|
|
|
|
|
|
|
--------------- |
4914
|
|
|
|
|
|
|
|
4915
|
|
|
|
|
|
|
The commands listed below can be used to modify the default behavior of |
4916
|
|
|
|
|
|
|
the XML parser or XSH2 itself. Some of the commands switch between two |
4917
|
|
|
|
|
|
|
different modes according to a given expression (which is expected to |
4918
|
|
|
|
|
|
|
result either in zero or non-zero value). Other commands also working as |
4919
|
|
|
|
|
|
|
a flip-flop have their own explicit counterparts (e.g. [verbose] and |
4920
|
|
|
|
|
|
|
[quiet] or [debug] and [nodebug]). This inconsistency is due to |
4921
|
|
|
|
|
|
|
historical reasons. |
4922
|
|
|
|
|
|
|
|
4923
|
|
|
|
|
|
|
The [encoding] and [query-encoding] settings allow to specify character |
4924
|
|
|
|
|
|
|
encodings of user's input and XSH2's own output. This is particularly |
4925
|
|
|
|
|
|
|
useful when you work with UTF-8 encoded documents on a console which only |
4926
|
|
|
|
|
|
|
supports 8-bit characters. |
4927
|
|
|
|
|
|
|
|
4928
|
|
|
|
|
|
|
The [settings] command displays current settings by means of XSH2 |
4929
|
|
|
|
|
|
|
commands. Thus it can not only be used to review current values, but also |
4930
|
|
|
|
|
|
|
to store them for future use, e.g. in ~/.xsh2rc file. |
4931
|
|
|
|
|
|
|
|
4932
|
|
|
|
|
|
|
Example: |
4933
|
|
|
|
|
|
|
xsh> settings | cat > ~/.xsh2rc |
4934
|
|
|
|
|
|
|
|
4935
|
|
|
|
|
|
|
|
4936
|
|
|
|
|
|
|
Related help items: |
4937
|
|
|
|
|
|
|
backups, debug, empty-tags, encoding, indent, keep-blanks, load-ext-dtd, |
4938
|
|
|
|
|
|
|
nobackups, nodebug, parser-completes-attributes, parser-expands-entities, |
4939
|
|
|
|
|
|
|
parser-expands-xinclude, pedantic-parser, query-encoding, quiet, |
4940
|
|
|
|
|
|
|
recovering, register-function, register-namespace, |
4941
|
|
|
|
|
|
|
register-xhtml-namespace, register-xsh-namespace, run-mode, settings, |
4942
|
|
|
|
|
|
|
skip-dtd, switch-to-new-documents, test-mode, unregister-function, |
4943
|
|
|
|
|
|
|
unregister-namespace, validation, verbose, xpath-axis-completion, |
4944
|
|
|
|
|
|
|
xpath-completion, xpath-extensions |
4945
|
|
|
|
|
|
|
|
4946
|
|
|
|
|
|
|
END |
4947
|
|
|
|
|
|
|
|
4948
|
|
|
|
|
|
|
$HELP{'Perl_shell'}=[<<'END']; |
4949
|
|
|
|
|
|
|
Interacting with Perl and Shell |
4950
|
|
|
|
|
|
|
------------------------------- |
4951
|
|
|
|
|
|
|
|
4952
|
|
|
|
|
|
|
Along with XPath, Perl is one of two XSH2 expression languages, and |
4953
|
|
|
|
|
|
|
borrows XSH2 its great expressive power. Perl is a language optimized for |
4954
|
|
|
|
|
|
|
scanning arbitrary text files, extracting information from those text |
4955
|
|
|
|
|
|
|
files, and printing reports based on that information. It has built-in |
4956
|
|
|
|
|
|
|
regular expressions and powerful yet easy to learn data structures |
4957
|
|
|
|
|
|
|
(scalars, arrays, hash tables). It's also a good language for many system |
4958
|
|
|
|
|
|
|
management tasks. XSH2 itself is written in Perl (except for the XML |
4959
|
|
|
|
|
|
|
engine, which uses libxml2 library written in C by Daniel Veillard). |
4960
|
|
|
|
|
|
|
|
4961
|
|
|
|
|
|
|
Calling Perl |
4962
|
|
|
|
|
|
|
------------ |
4963
|
|
|
|
|
|
|
|
4964
|
|
|
|
|
|
|
Perl [expressions or blocks of code] can either be used as arguments to |
4965
|
|
|
|
|
|
|
any XSH2 command. One of them is [perl] command which simply evaluates |
4966
|
|
|
|
|
|
|
the given Perl block. Other commands, such as [map], even require Perl |
4967
|
|
|
|
|
|
|
expression argument and allow quickly change DOM node content. Perl |
4968
|
|
|
|
|
|
|
expressions may also provide lists of strings to iterate over with a |
4969
|
|
|
|
|
|
|
[foreach] loop, or serve as conditions for [if], [unless], and [while] |
4970
|
|
|
|
|
|
|
statements. |
4971
|
|
|
|
|
|
|
|
4972
|
|
|
|
|
|
|
To prevent conflict between XSH2 internals and the evaluated Perl code, |
4973
|
|
|
|
|
|
|
XSH2 runs such code in the context of a special namespace |
4974
|
|
|
|
|
|
|
'XML::XSH2::Map'. As described in the section [Variables], XSH2 string |
4975
|
|
|
|
|
|
|
variables may be accessed and possibly assigned from Perl code in the |
4976
|
|
|
|
|
|
|
most obvious way, since they actually are Perl variables defined in the |
4977
|
|
|
|
|
|
|
'XML::XSH2::Map' namespace. |
4978
|
|
|
|
|
|
|
|
4979
|
|
|
|
|
|
|
The interaction between XSH2 and Perl actually works the other way |
4980
|
|
|
|
|
|
|
round as well, so that you may call back XSH2 from the evaluated Perl |
4981
|
|
|
|
|
|
|
code. For this, Perl function 'xsh' is defined in the 'XML::XSH2::Map' |
4982
|
|
|
|
|
|
|
namespace. All parameters passed to this function are interpreted as |
4983
|
|
|
|
|
|
|
XSH2 commands. |
4984
|
|
|
|
|
|
|
|
4985
|
|
|
|
|
|
|
Moreover, the following Perl helper functions are defined: |
4986
|
|
|
|
|
|
|
|
4987
|
|
|
|
|
|
|
'xsh(string,....)' - evaluates given string(s) as XSH2 commands. |
4988
|
|
|
|
|
|
|
|
4989
|
|
|
|
|
|
|
'call(name)' - call a given XSH2 subroutine. |
4990
|
|
|
|
|
|
|
|
4991
|
|
|
|
|
|
|
'count(string)' - evaluates given string as an XPath expression and |
4992
|
|
|
|
|
|
|
returns either literal value of the result (in case of boolean, string |
4993
|
|
|
|
|
|
|
and float result type) or number of nodes in a returned node-set. |
4994
|
|
|
|
|
|
|
|
4995
|
|
|
|
|
|
|
'literal(string|object)' - if passed a string, evaluates it as a XSH2 |
4996
|
|
|
|
|
|
|
expression and returns the literal value of the result; if passed an |
4997
|
|
|
|
|
|
|
object, returns literal value of the object. For example, |
4998
|
|
|
|
|
|
|
'literal('$doc/expression')' returns the same value as |
4999
|
|
|
|
|
|
|
'count('string($doc/expression)')'. |
5000
|
|
|
|
|
|
|
|
5001
|
|
|
|
|
|
|
'serialize(string|object)' - if passed a string, it first evaluates the |
5002
|
|
|
|
|
|
|
string as a XSH2 expression to obtain a node-list object. Then it |
5003
|
|
|
|
|
|
|
serializes the object into XML. The resulting string is equal to the |
5004
|
|
|
|
|
|
|
output of the XSH2 command [ls] applied on the same expression or |
5005
|
|
|
|
|
|
|
object expression only without indentation and folding. |
5006
|
|
|
|
|
|
|
|
5007
|
|
|
|
|
|
|
'type(string|object)' - if passed a string, it first evaluates the |
5008
|
|
|
|
|
|
|
string as XSH2 expression to obtain a node-list object. It returns a |
5009
|
|
|
|
|
|
|
list of strings representing the types of nodes in the node-list |
5010
|
|
|
|
|
|
|
(ordered in the canonical document order). The returned type strings |
5011
|
|
|
|
|
|
|
are: 'element', 'attribute', 'text', 'cdata', 'pi', 'entity_reference', |
5012
|
|
|
|
|
|
|
'document', 'chunk', 'comment', 'namespace', 'unknown'. |
5013
|
|
|
|
|
|
|
|
5014
|
|
|
|
|
|
|
'nodelist(string|object,...)' - converts its arguments to objects if |
5015
|
|
|
|
|
|
|
necessary and returns a node-list consisting of the objects. |
5016
|
|
|
|
|
|
|
|
5017
|
|
|
|
|
|
|
'xpath(string, node?)' - evaluates a given string as an XPath |
5018
|
|
|
|
|
|
|
expression in the context of a given node and returns the result. |
5019
|
|
|
|
|
|
|
|
5020
|
|
|
|
|
|
|
'echo(string,...)' - prints given strings on XSH2 output. Note, that in |
5021
|
|
|
|
|
|
|
the interactive mode, XSH2 redirects all output to a specific terminal |
5022
|
|
|
|
|
|
|
file handle stored in the variable '$OUT'. So, if you for example mean |
5023
|
|
|
|
|
|
|
to pipe the result to a shell command, you should avoid using STDOUT |
5024
|
|
|
|
|
|
|
filehandle directly. You may either use the usual 'print' without a |
5025
|
|
|
|
|
|
|
filehandle, use the 'echo' function, or use '$OUT' as a filehandle. |
5026
|
|
|
|
|
|
|
|
5027
|
|
|
|
|
|
|
In the following examples we use Perl to populate the Middle-Earth with |
5028
|
|
|
|
|
|
|
Hobbits whose names are read from a text file called 'hobbits.txt', |
5029
|
|
|
|
|
|
|
unless there are some Hobbits in Middle-Earth already. |
5030
|
|
|
|
|
|
|
|
5031
|
|
|
|
|
|
|
Example: Use Perl to read text files |
5032
|
|
|
|
|
|
|
|
5033
|
|
|
|
|
|
|
unless (//creature[@race='hobbit']) { |
5034
|
|
|
|
|
|
|
perl { |
5035
|
|
|
|
|
|
|
open my $fh, "hobbits.txt" }; |
5036
|
|
|
|
|
|
|
@hobbits=<$file>; |
5037
|
|
|
|
|
|
|
close $fh; |
5038
|
|
|
|
|
|
|
} |
5039
|
|
|
|
|
|
|
foreach { @hobbits } { |
5040
|
|
|
|
|
|
|
copy xsh:new-element("creature","name",.,"race","hobbit") |
5041
|
|
|
|
|
|
|
into m:/middle-earth/creatures; |
5042
|
|
|
|
|
|
|
} |
5043
|
|
|
|
|
|
|
} |
5044
|
|
|
|
|
|
|
|
5045
|
|
|
|
|
|
|
Example: The same code as a single Perl block |
5046
|
|
|
|
|
|
|
|
5047
|
|
|
|
|
|
|
perl { |
5048
|
|
|
|
|
|
|
unless (count(//creature[@race='hobbit'])) { |
5049
|
|
|
|
|
|
|
open my $file, "hobbits.txt"; |
5050
|
|
|
|
|
|
|
foreach (<$file>) { |
5051
|
|
|
|
|
|
|
xsh(qq{insert element "" |
5052
|
|
|
|
|
|
|
into m:/middle-earth/creatures}); |
5053
|
|
|
|
|
|
|
} |
5054
|
|
|
|
|
|
|
close $file; |
5055
|
|
|
|
|
|
|
} |
5056
|
|
|
|
|
|
|
}; |
5057
|
|
|
|
|
|
|
|
5058
|
|
|
|
|
|
|
Writing your own XPath extension functions in Perl |
5059
|
|
|
|
|
|
|
-------------------------------------------------- |
5060
|
|
|
|
|
|
|
|
5061
|
|
|
|
|
|
|
XSH2 allows users to extend the set of XPath functions by providing |
5062
|
|
|
|
|
|
|
extension functions written in Perl. This can be achieved using the |
5063
|
|
|
|
|
|
|
[register-function] command. The perl code implementing an extension |
5064
|
|
|
|
|
|
|
function works as a usual perl routine accepting its arguments in '@_' |
5065
|
|
|
|
|
|
|
and returning the result. The following conventions are used: |
5066
|
|
|
|
|
|
|
|
5067
|
|
|
|
|
|
|
The arguments passed to the perl implementation by the XPath engine are |
5068
|
|
|
|
|
|
|
simple scalars for string, boolean and float argument types and |
5069
|
|
|
|
|
|
|
'XML::LibXML::NodeList' objects for node-set argument types. The |
5070
|
|
|
|
|
|
|
implementation is responsible for checking the argument number and |
5071
|
|
|
|
|
|
|
types. The implementation may use general Perl functions as well as |
5072
|
|
|
|
|
|
|
'XML::LibXML' methods to process the arguments and return the result. |
5073
|
|
|
|
|
|
|
Documentation for the 'XML::LibXML' Perl module can be found for |
5074
|
|
|
|
|
|
|
example at http://search.cpan.org/~pajas/XML-LibXML/. |
5075
|
|
|
|
|
|
|
|
5076
|
|
|
|
|
|
|
Extension functions SHOULD NOT MODIFY the document DOM tree. Doing so |
5077
|
|
|
|
|
|
|
could not only confuse the XPath engine but possibly even result in an |
5078
|
|
|
|
|
|
|
critical error (such as segmentation fault). Calling XSH2 commands from |
5079
|
|
|
|
|
|
|
extension function implementations is also dangerous and isn't |
5080
|
|
|
|
|
|
|
generally recommended. |
5081
|
|
|
|
|
|
|
|
5082
|
|
|
|
|
|
|
The extension function implementation must return a single value, which |
5083
|
|
|
|
|
|
|
can be of one of the following types: simple scalar (a number or |
5084
|
|
|
|
|
|
|
string), 'XML::LibXML::Boolean' object reference (result is a boolean |
5085
|
|
|
|
|
|
|
value), 'XML::LibXML::Literal' object reference (result is a string), |
5086
|
|
|
|
|
|
|
'XML::LibXML::Number' object reference (result is a float), |
5087
|
|
|
|
|
|
|
'XML::LibXML::Node' (or derived) object reference (result is a node-set |
5088
|
|
|
|
|
|
|
consisting of a single node), or 'XML::LibXML::NodeList' (result is a |
5089
|
|
|
|
|
|
|
node-set). For convenience, simple (non-blessed) array references |
5090
|
|
|
|
|
|
|
consisting of 'XML::LibXML::Node' objects can also be used for a |
5091
|
|
|
|
|
|
|
node-set result instead of a 'XML::LibXML::NodeList'. |
5092
|
|
|
|
|
|
|
|
5093
|
|
|
|
|
|
|
Calling the System Shell |
5094
|
|
|
|
|
|
|
------------------------ |
5095
|
|
|
|
|
|
|
|
5096
|
|
|
|
|
|
|
In the interactive mode, XSH2 interprets all lines starting with the |
5097
|
|
|
|
|
|
|
exclamation mark ('!') as shell commands and invokes the system shell |
5098
|
|
|
|
|
|
|
to interpret the line (this is to mimic FTP and similar command-line |
5099
|
|
|
|
|
|
|
interpreters). |
5100
|
|
|
|
|
|
|
|
5101
|
|
|
|
|
|
|
Example: |
5102
|
|
|
|
|
|
|
xsh> !ls -l |
5103
|
|
|
|
|
|
|
-rw-rw-r-- 1 pajas pajas 6355 Mar 14 17:08 Artistic |
5104
|
|
|
|
|
|
|
drwxrwxr-x 2 pajas users 128 Sep 1 10:09 CVS |
5105
|
|
|
|
|
|
|
-rw-r--r-- 1 pajas pajas 14859 Aug 26 15:19 ChangeLog |
5106
|
|
|
|
|
|
|
-rw-r--r-- 1 pajas pajas 2220 Mar 14 17:03 INSTALL |
5107
|
|
|
|
|
|
|
-rw-r--r-- 1 pajas pajas 18009 Jul 15 17:35 LICENSE |
5108
|
|
|
|
|
|
|
-rw-rw-r-- 1 pajas pajas 417 May 9 15:16 MANIFEST |
5109
|
|
|
|
|
|
|
-rw-rw-r-- 1 pajas pajas 126 May 9 15:16 MANIFEST.SKIP |
5110
|
|
|
|
|
|
|
-rw-r--r-- 1 pajas pajas 20424 Sep 1 11:04 Makefile |
5111
|
|
|
|
|
|
|
-rw-r--r-- 1 pajas pajas 914 Aug 26 14:32 Makefile.PL |
5112
|
|
|
|
|
|
|
-rw-r--r-- 1 pajas pajas 1910 Mar 14 17:17 README |
5113
|
|
|
|
|
|
|
-rw-r--r-- 1 pajas pajas 438 Aug 27 13:51 TODO |
5114
|
|
|
|
|
|
|
drwxrwxr-x 5 pajas users 120 Jun 15 10:35 blib |
5115
|
|
|
|
|
|
|
drwxrwxr-x 3 pajas users 1160 Sep 1 10:09 examples |
5116
|
|
|
|
|
|
|
drwxrwxr-x 4 pajas users 96 Jun 15 10:35 lib |
5117
|
|
|
|
|
|
|
-rw-rw-r-- 1 pajas pajas 0 Sep 1 16:23 pm_to_blib |
5118
|
|
|
|
|
|
|
drwxrwxr-x 4 pajas users 584 Sep 1 21:18 src |
5119
|
|
|
|
|
|
|
drwxrwxr-x 3 pajas users 136 Sep 1 10:09 t |
5120
|
|
|
|
|
|
|
-rw-rw-r-- 1 pajas pajas 50 Jun 16 00:06 test |
5121
|
|
|
|
|
|
|
drwxrwxr-x 3 pajas users 496 Sep 1 20:18 tools |
5122
|
|
|
|
|
|
|
-rwxr-xr-x 1 pajas pajas 5104 Aug 30 17:08 xsh |
5123
|
|
|
|
|
|
|
|
5124
|
|
|
|
|
|
|
To invoke a system shell command or program from the non-interactive |
5125
|
|
|
|
|
|
|
mode or from a complex XSH2 construction, use the [exec] command. |
5126
|
|
|
|
|
|
|
|
5127
|
|
|
|
|
|
|
Since UNIX shell commands are very powerful tool for processing textual |
5128
|
|
|
|
|
|
|
data, XSH2 supports direct redirection of XSH2 commands output to |
5129
|
|
|
|
|
|
|
system shell command. This is very similarly to the redirection known |
5130
|
|
|
|
|
|
|
from UNIX shells, except that here, of course, the first command in the |
5131
|
|
|
|
|
|
|
pipe-line colone is an XSH2 [command]. Since semicolon (';') is used in |
5132
|
|
|
|
|
|
|
XSH2 to separate commands, it has to be prefixed with a backslash if it |
5133
|
|
|
|
|
|
|
should be used for other purposes. |
5134
|
|
|
|
|
|
|
|
5135
|
|
|
|
|
|
|
Example: Use grep and less to display context of `funny' |
5136
|
|
|
|
|
|
|
|
5137
|
|
|
|
|
|
|
xsh> ls //chapter[5]/para | grep funny | less |
5138
|
|
|
|
|
|
|
|
5139
|
|
|
|
|
|
|
Example: The same on Windows 2000/XP systems |
5140
|
|
|
|
|
|
|
|
5141
|
|
|
|
|
|
|
xsh> ls //chapter[5]/para | find "funny" | more |
5142
|
|
|
|
|
|
|
|
5143
|
|
|
|
|
|
|
|
5144
|
|
|
|
|
|
|
Related help items: |
5145
|
|
|
|
|
|
|
exec, hash, lcd, map, perl, rename |
5146
|
|
|
|
|
|
|
|
5147
|
|
|
|
|
|
|
END |
5148
|
|
|
|
|
|
|
|
5149
|
|
|
|
|
|
|
$HELP{'Prompt'}=[<<'END']; |
5150
|
|
|
|
|
|
|
Prompt in the interactive shell |
5151
|
|
|
|
|
|
|
------------------------------- |
5152
|
|
|
|
|
|
|
|
5153
|
|
|
|
|
|
|
Like many other shells, XSH2 provides means for customizing the format of |
5154
|
|
|
|
|
|
|
its interactive shell prompt. The prompt is displayed according to the |
5155
|
|
|
|
|
|
|
content of the variable '$PROMPT' on which the following substitutions |
5156
|
|
|
|
|
|
|
and interpolations are performed (in this order): |
5157
|
|
|
|
|
|
|
|
5158
|
|
|
|
|
|
|
1. Prompt-string replacements |
5159
|
|
|
|
|
|
|
|
5160
|
|
|
|
|
|
|
%% - percent sign |
5161
|
|
|
|
|
|
|
%p - XPath location of the current node |
5162
|
|
|
|
|
|
|
%P - like %p but without an initial document variable |
5163
|
|
|
|
|
|
|
%l - XPath location of the current node with ID-shortcuts |
5164
|
|
|
|
|
|
|
%L - like %l but without an initial document variable |
5165
|
|
|
|
|
|
|
%n - name of the current node |
5166
|
|
|
|
|
|
|
%N - local name of the current node |
5167
|
|
|
|
|
|
|
%c - canonical XPath name of the current node |
5168
|
|
|
|
|
|
|
%y - type of the current node (element,attribute,...) |
5169
|
|
|
|
|
|
|
%i - ID of the current node |
5170
|
|
|
|
|
|
|
%d - current document variable |
5171
|
|
|
|
|
|
|
%h - the hostname up to the first '.' |
5172
|
|
|
|
|
|
|
%H - the hostname |
5173
|
|
|
|
|
|
|
%s - XSH shell name (basename of $0) |
5174
|
|
|
|
|
|
|
%t - the current time in 24-hour HH:MM:SS format |
5175
|
|
|
|
|
|
|
%T - the current time in 12-hour HH:MM:SS format |
5176
|
|
|
|
|
|
|
%@ - the current time in 12-hour am/pm format |
5177
|
|
|
|
|
|
|
%A - the current time in 24-hour HH:MM format |
5178
|
|
|
|
|
|
|
%u - the username of the current user |
5179
|
|
|
|
|
|
|
%v - the version of XSH2 (e.g., 2.1.0) |
5180
|
|
|
|
|
|
|
%V - the revision number of XML::XSH2::Functions (e.g. 2.40) |
5181
|
|
|
|
|
|
|
%w - current working directory (on the local filesystem) |
5182
|
|
|
|
|
|
|
%W - basename of %w |
5183
|
|
|
|
|
|
|
2. Variable, XPath and Perl interpolations |
5184
|
|
|
|
|
|
|
|
5185
|
|
|
|
|
|
|
Substrings of the forms '${variable}', '${{...perl...}}' and |
5186
|
|
|
|
|
|
|
'${(...xpath...)}' are interpolated as in XSH2 [expressions]. |
5187
|
|
|
|
|
|
|
|
5188
|
|
|
|
|
|
|
3. Special character substitution |
5189
|
|
|
|
|
|
|
|
5190
|
|
|
|
|
|
|
\n - newline character |
5191
|
|
|
|
|
|
|
\r - line-feed character |
5192
|
|
|
|
|
|
|
\t - tab character |
5193
|
|
|
|
|
|
|
\a - bell character |
5194
|
|
|
|
|
|
|
\b - backspace character |
5195
|
|
|
|
|
|
|
\f - form feed character |
5196
|
|
|
|
|
|
|
\e - escape character (\033) |
5197
|
|
|
|
|
|
|
\\ - backslash character |
5198
|
|
|
|
|
|
|
\nnn - the character corresponding to the octal number nnn |
5199
|
|
|
|
|
|
|
(useful for non-printable terminal control characters) |
5200
|
|
|
|
|
|
|
The default value of '$PROMPT' is '"%p>"'. |
5201
|
|
|
|
|
|
|
|
5202
|
|
|
|
|
|
|
Note that you must escape '${...}' interpolators like '\${...}' if you |
5203
|
|
|
|
|
|
|
want them to be evaluated at each prompt rather than at the time of the |
5204
|
|
|
|
|
|
|
assignment to '$PROMPT'. For example: |
5205
|
|
|
|
|
|
|
|
5206
|
|
|
|
|
|
|
Example: Let `uname` be computed once, `date` at every prompt |
5207
|
|
|
|
|
|
|
|
5208
|
|
|
|
|
|
|
$PROMPT="[${{ chomp($u=`uname`);$u }} \${{ chomp($d=`date`);$d }}] %p>" |
5209
|
|
|
|
|
|
|
|
5210
|
|
|
|
|
|
|
END |
5211
|
|
|
|
|
|
|
|
5212
|
|
|
|
|
|
|
$HELP{'xsh2delta'}=[<<'END']; |
5213
|
|
|
|
|
|
|
Changes since XSH 1.x |
5214
|
|
|
|
|
|
|
--------------------- |
5215
|
|
|
|
|
|
|
|
5216
|
|
|
|
|
|
|
This section briefly describes differences between XSH2 and previous XSH |
5217
|
|
|
|
|
|
|
1.x releases. The list should not be considered complete. Some syntax |
5218
|
|
|
|
|
|
|
variations or amendments in the semantics of various commands may not be |
5219
|
|
|
|
|
|
|
documented in this section, neither are various improvements in the XSH |
5220
|
|
|
|
|
|
|
interpreter. |
5221
|
|
|
|
|
|
|
|
5222
|
|
|
|
|
|
|
Changes in XSH2 |
5223
|
|
|
|
|
|
|
--------------- |
5224
|
|
|
|
|
|
|
|
5225
|
|
|
|
|
|
|
1. In XSH2, subroutines can be called without a [call]. They can be |
5226
|
|
|
|
|
|
|
[redefined] and [undefined]. The command [call] can still be used, |
5227
|
|
|
|
|
|
|
but it's use only makes sense in indirect calls, where subroutine's |
5228
|
|
|
|
|
|
|
name is computed from an expression. |
5229
|
|
|
|
|
|
|
|
5230
|
|
|
|
|
|
|
def foo $param1 $param2 { |
5231
|
|
|
|
|
|
|
# param1 and $param2 are lexical (a.k.a. my) |
5232
|
|
|
|
|
|
|
ls $param1; |
5233
|
|
|
|
|
|
|
echo $param2 |
5234
|
|
|
|
|
|
|
} |
5235
|
|
|
|
|
|
|
foo (//chapter)[1] (//chapter)[1]/title |
5236
|
|
|
|
|
|
|
|
5237
|
|
|
|
|
|
|
def inc $param1 { return ($param1 + 1) } |
5238
|
|
|
|
|
|
|
$two := inc 1; |
5239
|
|
|
|
|
|
|
2. XSH2 uses variables of the form [$variable] for all kinds of |
5240
|
|
|
|
|
|
|
objects, including node-sets (which, if evaluated as Perl |
5241
|
|
|
|
|
|
|
expressions, preserve node order). Node-list variables of XSH 1.x |
5242
|
|
|
|
|
|
|
have been deprecated. |
5243
|
|
|
|
|
|
|
|
5244
|
|
|
|
|
|
|
$var = //foo/bar; # node set |
5245
|
|
|
|
|
|
|
$var = "hallo world"; # string |
5246
|
|
|
|
|
|
|
$var = xsh:new-element("foo"); # node object |
5247
|
|
|
|
|
|
|
$var = { ['a','b','c'] }; # Perl array reference |
5248
|
|
|
|
|
|
|
$var = {{ 'a'=>'A', 'b'=>'B' }}; # Perl hash reference |
5249
|
|
|
|
|
|
|
3. XSH2 allows variables to be used in XPath just as they are used in |
5250
|
|
|
|
|
|
|
XSLT: |
5251
|
|
|
|
|
|
|
|
5252
|
|
|
|
|
|
|
$var = //foo/bar; |
5253
|
|
|
|
|
|
|
ls //baz[ . = $var[@test=1]/any ] |
5254
|
|
|
|
|
|
|
Variable interpolation is still available in XSH2 via ${var}, but |
5255
|
|
|
|
|
|
|
it's importance is diminished compared to XSH 1.x, because the XPath |
5256
|
|
|
|
|
|
|
engine now evaluates variables directly. Interpolation can still be |
5257
|
|
|
|
|
|
|
used for things like "XPath-macros": |
5258
|
|
|
|
|
|
|
|
5259
|
|
|
|
|
|
|
$filter = "[ . = $var[@test=1]/any ]"; |
5260
|
|
|
|
|
|
|
ls //baz${filter}; |
5261
|
|
|
|
|
|
|
4. XSH2 equally supports XPath and Perl [expressions] (written in |
5262
|
|
|
|
|
|
|
braces { ... }). Unfortunately, Perl expressions can't be embedded in |
5263
|
|
|
|
|
|
|
XPath [expressions], but one can still use variables as an agent: |
5264
|
|
|
|
|
|
|
|
5265
|
|
|
|
|
|
|
perl { use MIME::Base64 }; |
5266
|
|
|
|
|
|
|
my $encoded = { encode_base64('open sesame') } |
5267
|
|
|
|
|
|
|
ls //secret-cave[string(password) = $encoded] |
5268
|
|
|
|
|
|
|
We can, however, use Perl-only expressions complemented with |
5269
|
|
|
|
|
|
|
auto-conversion to do things like: |
5270
|
|
|
|
|
|
|
|
5271
|
|
|
|
|
|
|
copy { encode_base64('Pe do mellon a minno!') } replace //secret-cave/password/text(); |
5272
|
|
|
|
|
|
|
5. Commands return values (see [:= assignment], or [&{ } |
5273
|
|
|
|
|
|
|
expressions]). |
5274
|
|
|
|
|
|
|
|
5275
|
|
|
|
|
|
|
$moved_paras := xmove //para replace .; |
5276
|
|
|
|
|
|
|
$chapter := wrap chapter $moved_paras; |
5277
|
|
|
|
|
|
|
ls $chapter; |
5278
|
|
|
|
|
|
|
|
5279
|
|
|
|
|
|
|
# or just |
5280
|
|
|
|
|
|
|
|
5281
|
|
|
|
|
|
|
ls &{ wrap chapter &{ xmove //para replace . } }; |
5282
|
|
|
|
|
|
|
6. XSH2 deprecates "string" expressions of XSH 1.x. However, for |
5283
|
|
|
|
|
|
|
convenience, some XSH2 commands interpret name-like XPath expressions |
5284
|
|
|
|
|
|
|
on certain argument positions as strings (mostly commands that expect |
5285
|
|
|
|
|
|
|
file-name or node-name arguments): |
5286
|
|
|
|
|
|
|
|
5287
|
|
|
|
|
|
|
insert element my_document into .; |
5288
|
|
|
|
|
|
|
insert text "foo" into my_document; |
5289
|
|
|
|
|
|
|
|
5290
|
|
|
|
|
|
|
$doc := open my_document; # opens file named "my_document" |
5291
|
|
|
|
|
|
|
$doc := open "my_document"; # same |
5292
|
|
|
|
|
|
|
$doc := open (my_document); # opens file named "foo" |
5293
|
|
|
|
|
|
|
$doc := open string(my_document); # same |
5294
|
|
|
|
|
|
|
7. In XSH2, XML documents have no ID. They are referred to using |
5295
|
|
|
|
|
|
|
variables (which fits in well with the unified variable concept): |
5296
|
|
|
|
|
|
|
|
5297
|
|
|
|
|
|
|
$doc1 := open "foo1.xml"; |
5298
|
|
|
|
|
|
|
$doc2 := open "foo2.xml"; |
5299
|
|
|
|
|
|
|
ls ($doc1//para|$doc2//para); |
5300
|
|
|
|
|
|
|
cd $doc1; |
5301
|
|
|
|
|
|
|
ls id('intro'); # finds ID intro in the current document ($doc1) |
5302
|
|
|
|
|
|
|
ls xsh:id2($doc2, 'intro'); # finds ID intro in $doc2 |
5303
|
|
|
|
|
|
|
8. XSH2 commands have options and flags instead of many optional |
5304
|
|
|
|
|
|
|
(positional) arguments. Options/flags usually have both long forms |
5305
|
|
|
|
|
|
|
(like --flag) and equivalent short forms (like :f) (colon is borrowed |
5306
|
|
|
|
|
|
|
from Scheme, because dash is reserved for XPath minus). |
5307
|
|
|
|
|
|
|
|
5308
|
|
|
|
|
|
|
$doc := open --format html "version1.html"; |
5309
|
|
|
|
|
|
|
save --file "version2.xml" $doc; |
5310
|
|
|
|
|
|
|
|
5311
|
|
|
|
|
|
|
ls --fold /; |
5312
|
|
|
|
|
|
|
ls :f /; |
5313
|
|
|
|
|
|
|
ls --depth 1 /; |
5314
|
|
|
|
|
|
|
ls :d 1 /; |
5315
|
|
|
|
|
|
|
|
5316
|
|
|
|
|
|
|
# all the same: |
5317
|
|
|
|
|
|
|
$sorted = sort --key @name --locale --descending //user; |
5318
|
|
|
|
|
|
|
$sorted = sort :l:d:k@name //user; |
5319
|
|
|
|
|
|
|
$sorted = sort --key @name --compare { use locale; $b cmp $a } //user; |
5320
|
|
|
|
|
|
|
|
5321
|
|
|
|
|
|
|
validate --relaxng --file "test.rng" $mydoc; |
5322
|
|
|
|
|
|
|
validate --public "-//OASIS//DTD DocBook XML V4.1.2//EN" $mydoc; |
5323
|
|
|
|
|
|
|
validate --yesno $mydoc; |
5324
|
|
|
|
|
|
|
9. Finally, [eval] is no longer an alias for [perl] in XSH2, but |
5325
|
|
|
|
|
|
|
instead evaluates strings containing XSH2 commands (so 'eval $string' |
5326
|
|
|
|
|
|
|
now practically works like old ugly 'perl { xsh($string) }'). See the |
5327
|
|
|
|
|
|
|
documentation for [eval] for a handy usage example (no more PHP, XSTL |
5328
|
|
|
|
|
|
|
and XPathScript :-)). |
5329
|
|
|
|
|
|
|
|
5330
|
|
|
|
|
|
|
Examples |
5331
|
|
|
|
|
|
|
-------- |
5332
|
|
|
|
|
|
|
|
5333
|
|
|
|
|
|
|
Example: Open command has changed. |
5334
|
|
|
|
|
|
|
|
5335
|
|
|
|
|
|
|
XSH1: |
5336
|
|
|
|
|
|
|
foo = file.xml; |
5337
|
|
|
|
|
|
|
or |
5338
|
|
|
|
|
|
|
foo = "file.xml"; |
5339
|
|
|
|
|
|
|
XSH2: |
5340
|
|
|
|
|
|
|
$foo := open file.xml; # file.xml is a bareword in file-name context |
5341
|
|
|
|
|
|
|
or |
5342
|
|
|
|
|
|
|
$foo := open "file.xml"; # "file.xml" is a XPath string |
5343
|
|
|
|
|
|
|
or |
5344
|
|
|
|
|
|
|
$foo := open {"file.xml"}; # "file.xml" is a Perl string |
5345
|
|
|
|
|
|
|
or |
5346
|
|
|
|
|
|
|
$foo = xsh:open("file.xml"); # righthand side is an XPath extension function |
5347
|
|
|
|
|
|
|
|
5348
|
|
|
|
|
|
|
Example: XSH2 commands have options |
5349
|
|
|
|
|
|
|
|
5350
|
|
|
|
|
|
|
XSH1: |
5351
|
|
|
|
|
|
|
open HTML FILE foo2 = "file.html"; |
5352
|
|
|
|
|
|
|
XSH2: |
5353
|
|
|
|
|
|
|
$foo2 := open --format html "file.html"; |
5354
|
|
|
|
|
|
|
|
5355
|
|
|
|
|
|
|
Example: documents |
5356
|
|
|
|
|
|
|
|
5357
|
|
|
|
|
|
|
XSH1: |
5358
|
|
|
|
|
|
|
foo = file.xml; |
5359
|
|
|
|
|
|
|
ls foo:(//bar|//baz); |
5360
|
|
|
|
|
|
|
XSH2: |
5361
|
|
|
|
|
|
|
$foo := open file.xml; |
5362
|
|
|
|
|
|
|
ls ($foo//bar|$foo//baz); |
5363
|
|
|
|
|
|
|
|
5364
|
|
|
|
|
|
|
Example: variable interpretation |
5365
|
|
|
|
|
|
|
|
5366
|
|
|
|
|
|
|
XSH1: |
5367
|
|
|
|
|
|
|
$family = "Arial"; |
5368
|
|
|
|
|
|
|
ls //font[@family="$family"]; # interpolation |
5369
|
|
|
|
|
|
|
or |
5370
|
|
|
|
|
|
|
ls //font[@family="${family}"]; # interpolation |
5371
|
|
|
|
|
|
|
XSH2: |
5372
|
|
|
|
|
|
|
$family = "Arial"; |
5373
|
|
|
|
|
|
|
ls //font[@family=$family]; # evaluation by XPath engine |
5374
|
|
|
|
|
|
|
or |
5375
|
|
|
|
|
|
|
ls //font[@family="${family}"]; # interpolation |
5376
|
|
|
|
|
|
|
|
5377
|
|
|
|
|
|
|
Example: adding new nodes |
5378
|
|
|
|
|
|
|
|
5379
|
|
|
|
|
|
|
XSH1: |
5380
|
|
|
|
|
|
|
insert attribute "foo=bar" into /scratch; |
5381
|
|
|
|
|
|
|
XSH2: |
5382
|
|
|
|
|
|
|
insert attribute "foo=bar" into /scratch; |
5383
|
|
|
|
|
|
|
or |
5384
|
|
|
|
|
|
|
copy xsh:new-attribute("foo","bar") into /scratch; |
5385
|
|
|
|
|
|
|
|
5386
|
|
|
|
|
|
|
Example: foreach with perl expression |
5387
|
|
|
|
|
|
|
|
5388
|
|
|
|
|
|
|
XSH1: |
5389
|
|
|
|
|
|
|
foreach { glob('*.xml') } { |
5390
|
|
|
|
|
|
|
open doc = $__; |
5391
|
|
|
|
|
|
|
... |
5392
|
|
|
|
|
|
|
} |
5393
|
|
|
|
|
|
|
XSH2: |
5394
|
|
|
|
|
|
|
foreach { glob('*.xml') } { |
5395
|
|
|
|
|
|
|
my $doc := open .; |
5396
|
|
|
|
|
|
|
... |
5397
|
|
|
|
|
|
|
} |
5398
|
|
|
|
|
|
|
|
5399
|
|
|
|
|
|
|
Example: foreach (perl expression) with variable |
5400
|
|
|
|
|
|
|
|
5401
|
|
|
|
|
|
|
XSH2: |
5402
|
|
|
|
|
|
|
foreach my $filename in { glob('*.xml') } { |
5403
|
|
|
|
|
|
|
my $doc := open $filename; |
5404
|
|
|
|
|
|
|
... |
5405
|
|
|
|
|
|
|
} |
5406
|
|
|
|
|
|
|
|
5407
|
|
|
|
|
|
|
Example: sorting nodes |
5408
|
|
|
|
|
|
|
|
5409
|
|
|
|
|
|
|
XSH1: |
5410
|
|
|
|
|
|
|
%list = //player; |
5411
|
|
|
|
|
|
|
sort @best_score { $a <=> $b } %list; |
5412
|
|
|
|
|
|
|
copy %list into .; |
5413
|
|
|
|
|
|
|
XSH2: |
5414
|
|
|
|
|
|
|
$list := sort --numeric --key @best_score //player; |
5415
|
|
|
|
|
|
|
copy { $list } into .; |
5416
|
|
|
|
|
|
|
or |
5417
|
|
|
|
|
|
|
copy &{ sort --numeric --key @best_score //player } into .; |
5418
|
|
|
|
|
|
|
or (using short options) |
5419
|
|
|
|
|
|
|
copy &{ sort :n :k @best_score //player } into .; |
5420
|
|
|
|
|
|
|
|
5421
|
|
|
|
|
|
|
END |
5422
|
|
|
|
|
|
|
|
5423
|
|
|
|
|
|
|
$HELP{'commands'}=$HELP{'command'}; |
5424
|
|
|
|
|
|
|
$Apropos = { |
5425
|
|
|
|
|
|
|
'quiet' => 'turn off many XSH2 messages', |
5426
|
|
|
|
|
|
|
'location' => 'relative destination specification (such as after, before, etc.)', |
5427
|
|
|
|
|
|
|
'edit-string' => 'Edit a string or variable in a text editor.', |
5428
|
|
|
|
|
|
|
'perl' => 'evaluate in-line Perl code', |
5429
|
|
|
|
|
|
|
'xsh:join' => undef, |
5430
|
|
|
|
|
|
|
'xpath' => 'XPath expression', |
5431
|
|
|
|
|
|
|
'try' => 'try/catch statement', |
5432
|
|
|
|
|
|
|
'xsh:strmax' => undef, |
5433
|
|
|
|
|
|
|
'print' => 'print stuff on standard or standard error output', |
5434
|
|
|
|
|
|
|
'nodebug' => 'turn off debugging messages', |
5435
|
|
|
|
|
|
|
'register-xsh-namespace' => 'register a prefix for the XSH2 namespace', |
5436
|
|
|
|
|
|
|
'move' => 'move nodes (in the one-to-one mode)', |
5437
|
|
|
|
|
|
|
'xsh:lookup' => undef, |
5438
|
|
|
|
|
|
|
'xsh:times' => undef, |
5439
|
|
|
|
|
|
|
'xpath-completion' => 'turn on/off TAB completion for xpath expressions in the interactive mode', |
5440
|
|
|
|
|
|
|
'dtd' => 'show document\'s DTD', |
5441
|
|
|
|
|
|
|
'xsh:current' => undef, |
5442
|
|
|
|
|
|
|
'declare-ns' => 'create a special attribute declaring an XML namespace (EXPERIMENTAL)', |
5443
|
|
|
|
|
|
|
'xsh:min' => undef, |
5444
|
|
|
|
|
|
|
'nobackups' => 'turn off backup file creation', |
5445
|
|
|
|
|
|
|
'xsh:max' => undef, |
5446
|
|
|
|
|
|
|
'clone' => 'clone a given document', |
5447
|
|
|
|
|
|
|
'wrap' => 'wrap given nodes into elements', |
5448
|
|
|
|
|
|
|
'xsh:base-uri' => undef, |
5449
|
|
|
|
|
|
|
'xinsert' => 'create nodes on all target locations', |
5450
|
|
|
|
|
|
|
'xsh:new-pi' => undef, |
5451
|
|
|
|
|
|
|
'edit' => 'Edit parts of a XML document in a text editor.', |
5452
|
|
|
|
|
|
|
'xsh:new-cdata' => undef, |
5453
|
|
|
|
|
|
|
'enc' => 'show document\'s original character encoding', |
5454
|
|
|
|
|
|
|
'count' => 'calculate a [expression] and enumerate node-lists', |
5455
|
|
|
|
|
|
|
'xsh:if' => undef, |
5456
|
|
|
|
|
|
|
'xsh:lineno' => undef, |
5457
|
|
|
|
|
|
|
'xsh:reverse' => undef, |
5458
|
|
|
|
|
|
|
'query-encoding' => 'declare the charset of XSH2 source files and terminal input', |
5459
|
|
|
|
|
|
|
'prev' => 'restart an iteration on a previous node', |
5460
|
|
|
|
|
|
|
'xsh:new-text' => undef, |
5461
|
|
|
|
|
|
|
'set-standalone' => 'set document\'s standalone flag', |
5462
|
|
|
|
|
|
|
'xsh:var' => undef, |
5463
|
|
|
|
|
|
|
'change-ns-uri' => 'change namespace URI (EXPERIMENTAL)', |
5464
|
|
|
|
|
|
|
'xsh:path' => undef, |
5465
|
|
|
|
|
|
|
'xsh:ucfirst' => undef, |
5466
|
|
|
|
|
|
|
'eval' => 'evaluate given expression as XSH commands', |
5467
|
|
|
|
|
|
|
'backups' => 'turn on backup file creation', |
5468
|
|
|
|
|
|
|
'create' => 'make a new document from a given XML fragment', |
5469
|
|
|
|
|
|
|
'xsh:map' => undef, |
5470
|
|
|
|
|
|
|
'get' => 'calculate a given expression and return the result.', |
5471
|
|
|
|
|
|
|
'xsh:new-element-ns' => undef, |
5472
|
|
|
|
|
|
|
'pedantic-parser' => 'make the parser more pedantic', |
5473
|
|
|
|
|
|
|
'cd' => 'change current context node', |
5474
|
|
|
|
|
|
|
'recovering' => 'turn on/off parser\'s ability to fix broken XML', |
5475
|
|
|
|
|
|
|
'while' => 'simple while loop', |
5476
|
|
|
|
|
|
|
'parser-completes-attributes' => 'turn on/off parser\'s ability to fill default attribute values', |
5477
|
|
|
|
|
|
|
'unregister-function' => 'undefine extension function (EXPERIMENTAL)', |
5478
|
|
|
|
|
|
|
'next' => 'start the next iteration of an enclosing loop', |
5479
|
|
|
|
|
|
|
'xsh:id2' => undef, |
5480
|
|
|
|
|
|
|
'help' => 'on-line documentation', |
5481
|
|
|
|
|
|
|
'namespaces' => 'List namespaces available in a context of a given nodes', |
5482
|
|
|
|
|
|
|
'ls' => 'list a given part of a document as XML', |
5483
|
|
|
|
|
|
|
'register-function' => 'define XPath extension function (EXPERIMENTAL)', |
5484
|
|
|
|
|
|
|
'xsh:filename' => undef, |
5485
|
|
|
|
|
|
|
'document' => 'specifying documents', |
5486
|
|
|
|
|
|
|
'set-dtd' => 'set document\'s DTD declaration', |
5487
|
|
|
|
|
|
|
'stream' => 'process selected elements from an XML stream (EXPERIMENTAL)', |
5488
|
|
|
|
|
|
|
'version' => 'show version information', |
5489
|
|
|
|
|
|
|
'xsh:substr' => undef, |
5490
|
|
|
|
|
|
|
'last' => 'immediately exit an enclosing loop', |
5491
|
|
|
|
|
|
|
'return' => 'return from a subroutine', |
5492
|
|
|
|
|
|
|
'set-ns' => 'set namespace of the current node (EXPERIMENTAL)', |
5493
|
|
|
|
|
|
|
'expression' => 'expression argument type', |
5494
|
|
|
|
|
|
|
'xsh:split' => undef, |
5495
|
|
|
|
|
|
|
'xcopy' => 'copy nodes (in the all-to-every mode)', |
5496
|
|
|
|
|
|
|
'map' => 'transform node value/data using Perl or XPath expression', |
5497
|
|
|
|
|
|
|
'xsh:uc' => undef, |
5498
|
|
|
|
|
|
|
'switch-to-new-documents' => 'set on/off changing current document to newly open/created files', |
5499
|
|
|
|
|
|
|
'def' => 'sub-routine declaration', |
5500
|
|
|
|
|
|
|
'xsh:document-uri' => undef, |
5501
|
|
|
|
|
|
|
'normalize' => 'normalizes adjacent textnodes', |
5502
|
|
|
|
|
|
|
'foreach' => 'loop iterating over a node-list or a perl array', |
5503
|
|
|
|
|
|
|
'xsh:new-chunk' => undef, |
5504
|
|
|
|
|
|
|
'assign' => 'variable assignment', |
5505
|
|
|
|
|
|
|
'rename' => 'quickly rename nodes with in-line Perl code', |
5506
|
|
|
|
|
|
|
'call' => 'indirect call to a user-defined routine (macro)', |
5507
|
|
|
|
|
|
|
'subroutine' => 'name of a sub-routine', |
5508
|
|
|
|
|
|
|
'load-ext-dtd' => 'turn on/off external DTD fetching', |
5509
|
|
|
|
|
|
|
'indent' => 'turn on/off pretty-printing', |
5510
|
|
|
|
|
|
|
'unregister-namespace' => 'unregister namespace prefix', |
5511
|
|
|
|
|
|
|
'include' => 'include another XSH2 source in current position', |
5512
|
|
|
|
|
|
|
'xsh:grep' => undef, |
5513
|
|
|
|
|
|
|
'run-mode' => 'switch into normal execution mode (quit [test-mode])', |
5514
|
|
|
|
|
|
|
'xmove' => 'move nodes (in the all-to-every mode)', |
5515
|
|
|
|
|
|
|
'xsh:span' => undef, |
5516
|
|
|
|
|
|
|
'type' => undef, |
5517
|
|
|
|
|
|
|
'locate' => 'show a given node location (as a canonical XPath)', |
5518
|
|
|
|
|
|
|
'node-type' => 'node type specification (such as element, attribute, etc.)', |
5519
|
|
|
|
|
|
|
'copy' => 'copy nodes (in the one-to-one mode)', |
5520
|
|
|
|
|
|
|
'do' => 'execute a given block of commands', |
5521
|
|
|
|
|
|
|
'set_filename' => 'change filename or URL associated with a document', |
5522
|
|
|
|
|
|
|
'exec' => 'execute a shell command', |
5523
|
|
|
|
|
|
|
'validate' => 'validate a document against a DTD, RelaxNG, or XSD schemas', |
5524
|
|
|
|
|
|
|
'xpath-axis-completion' => 'sets TAB completion for axes in xpath expressions in the interactive mode', |
5525
|
|
|
|
|
|
|
'xsh:new-comment' => undef, |
5526
|
|
|
|
|
|
|
'doc-info' => 'displays various information about a document', |
5527
|
|
|
|
|
|
|
'skip-dtd' => 'turn on/off serialization of DTD DOCTYPE declaration', |
5528
|
|
|
|
|
|
|
'filename' => 'specifying filenames', |
5529
|
|
|
|
|
|
|
'command' => 'List of XSH2 commands and their general syntax', |
5530
|
|
|
|
|
|
|
'wrap-span' => 'wrap spans of nodes into elements', |
5531
|
|
|
|
|
|
|
'redo' => 'restart the innermost enclosing loop block', |
5532
|
|
|
|
|
|
|
'set-enc' => 'set document\'s charset (encoding)', |
5533
|
|
|
|
|
|
|
'xsh:resolve-uri' => undef, |
5534
|
|
|
|
|
|
|
'throw' => 'throw an exception', |
5535
|
|
|
|
|
|
|
'xslt' => 'compile a XSLT stylesheet and/or transform a document with XSLT', |
5536
|
|
|
|
|
|
|
'xsh:new-attribute' => undef, |
5537
|
|
|
|
|
|
|
'xsh:documents' => undef, |
5538
|
|
|
|
|
|
|
'xsh:context' => undef, |
5539
|
|
|
|
|
|
|
'defs' => 'list all user-defined subroutines', |
5540
|
|
|
|
|
|
|
'register-namespace' => 'register namespace prefix to use XPath expressions', |
5541
|
|
|
|
|
|
|
'if' => 'if statement', |
5542
|
|
|
|
|
|
|
'pwd' => 'show current context node location (as a canonical XPath)', |
5543
|
|
|
|
|
|
|
'open' => 'load an XML, HTML, or Docbook SGML document from a file, pipe or URI', |
5544
|
|
|
|
|
|
|
'xsh:parse' => undef, |
5545
|
|
|
|
|
|
|
'xsh:sum' => undef, |
5546
|
|
|
|
|
|
|
'block' => 'a block of XSH2 commands', |
5547
|
|
|
|
|
|
|
'xsh:same' => undef, |
5548
|
|
|
|
|
|
|
'empty-tags' => 'turn on/off serialization of empty tags', |
5549
|
|
|
|
|
|
|
'keep-blanks' => 'turn on/off ignorable whitespace preservation', |
5550
|
|
|
|
|
|
|
'remove' => 'remove given nodes', |
5551
|
|
|
|
|
|
|
'iterate' => 'iterate a block over current subtree', |
5552
|
|
|
|
|
|
|
'parser-expands-entities' => 'turn on/off parser\'s tendency to expand entities', |
5553
|
|
|
|
|
|
|
'insert' => 'create a node in on a given target location', |
5554
|
|
|
|
|
|
|
'exit' => 'exit XSH2 shell', |
5555
|
|
|
|
|
|
|
'xsh:document' => undef, |
5556
|
|
|
|
|
|
|
'my' => 'Create a new lexically scoped variable', |
5557
|
|
|
|
|
|
|
'settings' => 'list current settings using XSH2 syntax', |
5558
|
|
|
|
|
|
|
'sort' => 'sort a given node-list by given criteria', |
5559
|
|
|
|
|
|
|
'apropos' => 'search the documentation', |
5560
|
|
|
|
|
|
|
'encoding' => 'choose output charset', |
5561
|
|
|
|
|
|
|
'xsh:new-element' => undef, |
5562
|
|
|
|
|
|
|
'lcd' => 'change system working directory', |
5563
|
|
|
|
|
|
|
'parser-expands-xinclude' => 'turn on/off transparent XInclude insertion by parser', |
5564
|
|
|
|
|
|
|
'xsh:matches' => undef, |
5565
|
|
|
|
|
|
|
'xsh:strmin' => undef, |
5566
|
|
|
|
|
|
|
'xupdate' => 'apply XUpdate commands on a document', |
5567
|
|
|
|
|
|
|
'validation' => 'turn on/off validation in XML parser', |
5568
|
|
|
|
|
|
|
'xsh:subst' => undef, |
5569
|
|
|
|
|
|
|
'xpath-extensions' => 'map predefined XSH2 XPath extension functions to no or other namespace', |
5570
|
|
|
|
|
|
|
'save' => 'save a document as XML or HTML', |
5571
|
|
|
|
|
|
|
'perl-code' => 'in-line code in Perl programming language', |
5572
|
|
|
|
|
|
|
'nodename' => 'specifying names of DOM nodes', |
5573
|
|
|
|
|
|
|
'close' => 'close document (without saving)', |
5574
|
|
|
|
|
|
|
'hash' => 'index selected nodes by some key value', |
5575
|
|
|
|
|
|
|
'unfold' => 'unfold elements folded with fold command', |
5576
|
|
|
|
|
|
|
'canonical' => 'serialize nodes as to canonical XML', |
5577
|
|
|
|
|
|
|
'documents' => 'display a list of open documents', |
5578
|
|
|
|
|
|
|
'change-ns-prefix' => 'change namespace prefix (EXPERIMENTAL)', |
5579
|
|
|
|
|
|
|
'set' => 'create or modify document content (EXPERIMENTAL)', |
5580
|
|
|
|
|
|
|
'unless' => 'negated if statement', |
5581
|
|
|
|
|
|
|
'lineno' => 'print line-numbers corresponding to matching nodes', |
5582
|
|
|
|
|
|
|
'undef' => 'undefine sub-routine or variable', |
5583
|
|
|
|
|
|
|
'verbose' => 'make XSH2 print many messages', |
5584
|
|
|
|
|
|
|
'catalog' => 'use a catalog file during all parsing processes', |
5585
|
|
|
|
|
|
|
'register-xhtml-namespace' => 'register a prefix for the XHTML namespace', |
5586
|
|
|
|
|
|
|
'xsh:match' => undef, |
5587
|
|
|
|
|
|
|
'process-xinclude' => 'load and insert XInclude sections', |
5588
|
|
|
|
|
|
|
'index' => 'index a static document for faster XPath lookup', |
5589
|
|
|
|
|
|
|
'xsh:doc' => undef, |
5590
|
|
|
|
|
|
|
'xsh:lc' => undef, |
5591
|
|
|
|
|
|
|
'ifinclude' => 'conditionally include another XSH2 source in current position', |
5592
|
|
|
|
|
|
|
'xsh:serialize' => undef, |
5593
|
|
|
|
|
|
|
'xsh:lcfirst' => undef, |
5594
|
|
|
|
|
|
|
'strip-whitespace' => 'strip leading and trailing whitespace', |
5595
|
|
|
|
|
|
|
'debug' => 'display many annoying debugging messages', |
5596
|
|
|
|
|
|
|
'local' => 'temporarily assign new value to a variable', |
5597
|
|
|
|
|
|
|
'xsh:evaluate' => undef, |
5598
|
|
|
|
|
|
|
'xsh:sprintf' => undef, |
5599
|
|
|
|
|
|
|
'$variable' => undef, |
5600
|
|
|
|
|
|
|
'variables' => 'list global variables', |
5601
|
|
|
|
|
|
|
'test-mode' => 'do not execute any command, only check the syntax', |
5602
|
|
|
|
|
|
|
'fold' => 'mark elements to be folded by list command' |
5603
|
|
|
|
|
|
|
}; |
5604
|
|
|
|
|
|
|
|
5605
|
|
|
|
|
|
|
1; |
5606
|
|
|
|
|
|
|
__END__ |