Hi Folks, Thank you Rick and Dimitre. This discussion has been excellent. Most notably, it has revealed that
there are many factors to consider when defining “empty element”. Here is the list of factors:
Whitespace If an element contains whitespace, should it be considered empty? For example, should the B element in this instance
document be considered empty: <Row> Suppose the element is preprocessed to strip whitespace. For example, if the element is processed by an XSLT program
that contains the instruction <xsl:strip-space elements="*"/> then it will be impossible for subsequent instructions to even know that the element originally
contained whitespace.
Comment If an element contains a comment, should it be considered empty? For example, should the B element in this instance
document be considered empty: <Row>
Processing Instruction If an element contains a processing instruction, should it be considered empty? For example, should the B element
in this instance document be considered empty: <Row>
Attribute If an element contains an attribute, should it be considered empty? For example, should the B element in this
instance document be considered empty: <Row>
Namespace If an element has a namespace declaration on the element, should it be considered empty? For example, should the
B element in this instance document be considered empty: <Row> Suppose there are no namespace declarations on the element, but there are
in-scope namespaces; is the element empty? Note that there will
always be at least one in-scope namespace. Implicit on the root element of every XML document is this namespace declaration: <Row xmlns:xml="http://www.w3.org/XML/1998/namespace"> Suppose the element is bound to a namespace; is the element empty?
My Definition of Empty Element An element is empty if and only if it has an element node and nothing else, and the only in-scope namespace is the xml namespace.
Thus, the element has no attributes, no text node, no comments, no PIs, and no namespace declarations. Here is a table showing examples of B elements that do and do not conform to my definition of empty:
XPath that Implements a Test for Empty Element The following XPath, when applied to the examples shown in the table, will yield the desired
results. Caveat: the whitespace has not been stripped by preprocessing (see the section titled Whitespace). empty( (
Yikes! For such a basic task—define empty element—that is a lot to take into consideration. /Roger |