Re: [xsl] Can a single XPath statement duplicate the functionality of this verbose <xsl:choose> statement?

Subject: Re: [xsl] Can a single XPath statement duplicate the functionality of this verbose <xsl:choose> statement?
From: Wendell Piez <wapiez@xxxxxxxxxxxxxxxx>
Date: Tue, 25 Oct 2011 10:24:03 -0400
Hi,

On 10/24/2011 7:33 PM, Michael Kay wrote:
Note that in the XDM model used by XPath 2.0 and XSLT 2.0:

(a) a document node can have multiple element children

(b) any node (document nodes, element nodes, even text nodes) can be
parentless, and thus be the root of a tree

although neither of these conditions will arise in a tree that results
from parsing well-formed XML.

The last point is important if you want to have an accounting for the muddle.


For various reasons including historical ones (SGML), XML documents are restricted to having a single element at the top level. This was and is often called the "root element".

Yet there may also be other constructs sitting next to it, such as comments and processing instructions, and since these too become nodes in the tree, it is useful to have a nominal root (a "document node" or "the root node" in XPath 1.0 parlance) to which they can all attach.

As Michael remarks, XDM (and indeed the XPath 1.0 model as well) does not impose the restriction that there can only be a single element child of a document node. It also does not require that every tree have a document node at the top.

So if you serialize, in XML syntax, a document with more than one element child of the document node, you will not get well-formed XML document, because it doesn't follow the rule "one element at the top". (This is the flip side of Mike's observation that you won't get a document with more than one element at the top from parsing an XML document.) You can, however, get a document fragment or "well-formed XML external parsed entity", which can be called into an XML document using an entity reference.

Cheers,
Wendell



--
======================================================================
Wendell Piez                            mailto:wapiez@xxxxxxxxxxxxxxxx
Mulberry Technologies, Inc.                http://www.mulberrytech.com
17 West Jefferson Street                    Direct Phone: 301/315-9635
Suite 207                                          Phone: 301/315-9631
Rockville, MD  20850                                 Fax: 301/315-8285
----------------------------------------------------------------------
  Mulberry Technologies: A Consultancy Specializing in SGML and XML
======================================================================

Current Thread