8. General use of get

At this point of the tutorial, you'll need to know the XPath standard to understand what follows.

The following macro is used to display in an external image viewer, the image referenced in the fileref attribute of explicitly or implicitly selected DocBook elements graphic or imagedata.

The image viewer used by this macro is an external program called gimp. It is launched using command start.

<command name="startImageViewer">
      <get context="$implicitElement/@fileref" 
           expression="uri-to-file-name(resolve-uri(.))" />
      <command name="start" parameter='gimp "%_"' />

The above macro shows how to use get at its best:

  1. First the context attribute, common to all XPath-based constructs get, set, test and match, is evaluated as a node set, using the document as a context node.

  2. The expression attribute, common to get, set and test, is evaluated as a string using the context node found in previous step.

    If get, set, test or match have no context attribute, the context node used to evaluate expression is the document node itself (that is, XPath "/").

The context attribute contains "$implicitElement/@fileref" which means attribute fileref of explicitly or implicitly selected element, because implicitElement is a predefined variable mapped to explicitly or implicitly selected element (more info. about this in next section).

The expression attribute contains "uri-to-file-name(resolve-uri(.))". "." is the fileref attribute node. resolve-uri() in XMLmind XML Editor - Support of XPath 1.0 and uri-to-file-name() in XMLmind XML Editor - Support of XPath 1.0 are two non-standard XPath functions which are used to resolve a relative URL and then to convert this URL to a file name (xv will not work if passed an URL).