Example 1: Assign XPath Results to JavaScript Variables

The code below will find all A elements on page, take the first one and assign the resulting HTML content to the myOutput variable.

<!--{

  var contextNode = X.get('//a')[0];
  var myOutput = X.html(".", contextNode);

}-->

The visibility scope for all variables created within custom statements is a template. It means you may access them inside the same template where it was created. For example, you may access the result by using value of statement like this:

<!--{= myOutput }-->

Or you may use declared contextNode variable for accessing desired results:

<a href="<!--{= X.value('@href', contextNode) }-->"><!--{= X.value('.', contextNode }--></a>