Command tie


tie Ties an xquery expression to a variable for ease of access


tie variable expression
tie variable


Tie associates an xquery expression to a variable so it can be queried more with a simplier syntax.
In the second form (with one argument only) the variable is untied.

The expression is any xquery expression and should be quoted or escaped. The expression is evaluated whenever the variable is accessed with either
the syntax



In the first case, the variable becomes context node for the xquery, and must be a single Item (may not be a sequence).
In the second case the variable is treated as a sequence, and the index'd element (1 based) is used as the context item.

In both cases, the text following the : is treated as a string and assigned to the $_ variable.


tie is very useful to access property or map like xml data.

For example, create a property object using xproperties

A=$<( xproperties -a a="A value" -a b="B value")
xecho $A

<properties version="1.0">
   <entry key="b">B value</entry>
   <entry key="a">A value</entry>

Now tie the variable A

tie A './/entry[@key = $_ ]/string()'

Now properties can be referenced by key value and returned as strings
echo ${A:a}

A value

Compare this to the equivalent expression needed to extract a property value

echo <[ $A//entry[@key="a"]/string() ]>


Tied variables survive resetting of the variable, so you can update variables and the tied expression is maintained.
Unlike the <[ ]> syntax, the tied xquery does NOT have access to the shell variables.

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