Lists Home |
Date Index |
> A couple of times people have suggested that XML should allow
> multiple top-level elements. Thinking about it, here is one possible
> approach that might fit in with existing systems with fairly minimal
> How does this fit in with XPath?
> At the moment, count(/*) always is 1.
That's not technically true: a document node in XPath can have
multiple element and text children -- it's able to represent any
well-formed external general parsed entity. It is true when you're
parsing a well-formed XML document, however.
> I am suggesting redefining / away from being the "document" to being
> the "resource", and then using indexing to get other entities. Two
> ways for this spring to mind:
> 1) Use existing XPaths, so that in the first example above the
> address of the y element is document("first example")/* The XPath
> of the document element is document("first example")/*
> 2) Use a new axis on XPath, for example
> /entity::* is the y element
> /entity::* is the document element,
> /x is shorthand for /entity::*/x and
> //x is shorthand for /entity::*//x
Here's a third possibility: in XPath 2.0, the collection() function
returns a sequence of nodes from a particular URL. In the case of a
file that contains multiple documents, collection("first example")
could return multiple document nodes, so you would use
collection("first example")/* to get the <y> element.
Such a document could also act as the input to a transformation. In
XSLT 2.0, the input() function returns a sequence of nodes as an
input, and in the case of a "resource"/"collection document" in the
format you suggest, this could be a sequence of document nodes. So if
your document was acting as the input to a transformation then
input()/* would return the <y> element.