blib/lib/XML/XSH2/Help.pm untested

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