Refenence to the original context

I am using a subset of XPath with the DOM to uniquely specify a node, where
sometimes the node is to be created if not found.  For example, one might
use an expression like “book[title = ‘Unix’ and author = ‘Frank
Adams-Watters’]” to find a child of the current (context) node of type
 “book”, with the specified child elements; and if not found, to create such
a node.  Basically, the syntax is limited to basic path specification, and
predicates using the “=” and “and” operators.  (Index predicates such as
“[2]” or the equivalent “[position() = 2]” are not currently supported but
should be.)  Not all axes are usable in this context; for example,
“descendant” is not, because it does not specify exactly where the new node
is to be created.  (Actually, I am currently using only the abbreviated
syntax, with “@” and the default child axis being the only ones supported,
but this should be enhanced at some future point.)

One problem comes when I want to support accessing elements by id.  An
expression like “id(@BookId)” works fine for finding an element, but if the
element is not found, I don’t know what kind of element to create or where
to create it.

The most straightforward way to try to deal with this is with something like
“/book[@id = @BookId]”.  The problem is that @BookId will be evaluated in
the context of the “book” element, not in the context of my base node.
There does not seem to be any way to write the predicate I want here.

Note that this problem is not restricted to node IDs; one might want to find
nodes from the root using other criteria taken from the starting, context
node.

One possible approach is to use a variable; for example, “book[@id =
$context/@BookId]”.  The problem with this is that the available variables
depend on the tool one is using.  (The tool I am using does not define any
variables nor allow me to supply such definitions.)  To handle this in a
general way, the XPath specification would need to specify a set of standard
variables that should be provided by any application.

A variation of this would be to allow variable definition as part of the
XPath string.  There are a large number of syntaxes that could be used for
such a definition.  One simple possibility would be to precede the path with
an assignment using a “=>” operator.  This would give us an expression like:
“. => context book[@id = $context/@BookId]”.  A variable definition
specified in the XPath string would supercede a definition of the same
variable name provided by the context.

Another approach is to add a new axis.  This would then give us something
like “book[@id = context::node()/@BookId]”.

Questions:

Is there some way I have missed to make this kind of node specification
using XPath?

Is there any interest in adding this kind of functionality to XPath?  If so,
how should it be added?

Is there any interest in formally defining a subset of XPath that can be
used to specify creation of a node, as described above

Received on Tuesday, 30 January 2001 19:26:23 UTC