Revision [1376]

This is an old revision of Lists made by DavePawson on 2010-05-11 05:56:05.

 

Plain sequences


Note that 'lists' are really sequences according to the XDM model, but don't let that put you off.

These are lists of items [sequences ] which might be strings for instance. Created with the '(' ... ')' notation. For example
ls=(a b c)

To access the command line parameters from a script, as, say 'xmlsh scriptname a.xml b.xml c.xml

parms=$*
for f in $parms
do
  echo $f
done

which will produce
a.xml
b.xml
c.xml 
on stdout



To retain the list nature of a command output, use the form ($var) e.g.

lst=$(ls)
for file in $lst
do
  echo $file
done


xml items


To form a 'list' of xml items, use the notation '<[item, item, item]>'
But note that the contents of the list can be any type valid for xml, including content from the current context, e.g.
ls=<[a, "b", //x[3]]>

which adds the content of element a (from the current context), a string "b" and the third x element from the root context.

Note the difference between the two types of list and use the appropriate form


Using variables holding sequences


The rule is
() creates a sequence {} preserves one when calling a function, another script or even calling an initial script.

given a seq in $x
x=(a b c)

y=$x  #y is now a list


To call a function with x as a parameter, use
functname param1 param2 {$x} is the required syntax


which ensures that the function receives, and can process $x as a sequence.



There are no comments on this page.
Valid XHTML :: Valid CSS: :: Powered by WikkaWiki