Revision [1064]

This is an old revision of CommandTie made by DavidLee on 2009-11-29 08:29:30.

 

Command tie


Name

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

Synopsis

tie variable expression

Description

Tie associates an xquery expression to a variable so it can be queried more with a simplier syntax.
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

${variable:arg}


or
${variable[index]:arg}


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.

Examples


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


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


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}


Result
A value


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

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



Notes


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.





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