From a76ef500c4b45b14dc19a92c42a2638235fc8aae Mon Sep 17 00:00:00 2001 From: Michael Kay Date: Thu, 21 Nov 2024 21:11:35 +0000 Subject: [PATCH 1/3] Rework rules for selecting a layout --- .../src/function-catalog.xml | 22 +- .../src/xpath-functions.xml | 493 ++++++++++++++---- 2 files changed, 394 insertions(+), 121 deletions(-) diff --git a/specifications/xpath-functions-40/src/function-catalog.xml b/specifications/xpath-functions-40/src/function-catalog.xml index 19666dac7..2f844c002 100644 --- a/specifications/xpath-functions-40/src/function-catalog.xml +++ b/specifications/xpath-functions-40/src/function-catalog.xml @@ -25719,12 +25719,13 @@ return json-to-xml($json, $options)]]>

The principles for conversion from elements to maps are described - in .

+ in , and the rules for selecting + an element layout for each element are given in .

In general, an element node maps to a key-value pair in which the key represents the element name, and the corresponding value represents the attributes and children of the element. In the case of a top-level element - (a node directly supplied in $nodes), the result will be a singleton map containing this key-value + (a node directly supplied in $elements), the result will be a singleton map containing this key-value pair as its only entry. In the case of a descendant element, the key-value pair for a child element will be added to the content representing its parent element, in a way that depends on the parent element's layout.

@@ -25732,16 +25733,7 @@ return json-to-xml($json, $options)]]> - -

A dynamic error is raised if the selected layout rules require atomization of an element that does not have a typed - value (typically because it has been validated against an element-only content model): .

-
- + @@ -25803,9 +25795,9 @@ return json-to-xml($json, $options)]]> --> - - Proposed for 4.0; initial review on 2023-06-27. - + +

New in 4.0.

+
diff --git a/specifications/xpath-functions-40/src/xpath-functions.xml b/specifications/xpath-functions-40/src/xpath-functions.xml index 423493e45..ead82289c 100644 --- a/specifications/xpath-functions-40/src/xpath-functions.xml +++ b/specifications/xpath-functions-40/src/xpath-functions.xml @@ -7756,7 +7756,7 @@ return

Achieving all three objectives requires design compromises. It also requires sacrificing some other desiderata. In consequence:

-

The conversion is not lossless.

+

The conversion is not lossless (see for details).

The conversion is not streamable.

The results are not necessarily compatible with those produced by other popular libraries.

@@ -7768,13 +7768,20 @@ return
by converting John]]> to { "name": {"#content":"John"} } and John]]> to { "name": { "@role":"first", "#content":"John" } }, - but this imposes unwanted complexity on the simplest cases. The solution adopted is twofold: firstly, - to make use of schema information where it is available, and secondly, to provide user - control over the mappings that are chosen.

+ but this imposes unwanted complexity on the simplest cases. The solution adopted is threefold:

+ +

The function makes use of schema information where available, so it considers + not just the structure of an individual element instance, but the rules governing the element type.

+

It is possible to request uniform layout for all elements sharing the same name, + so the decision is based on the structure of all elements with a given name, not just an individual + element.

+

It is possible to override the choice made by the system, and explicitly specify a layout + to be used for elements having a given name.

+
- + Element Layouts @@ -7870,15 +7877,16 @@ return

Layout name: the name to be used to select this layout in the $options parameter of the fn:elements-to-maps function.

Usage: the situations for which this layout is designed.

-

XML example: an example of a typical XML element for which this layout is appropriate.

-

JSON equivalent: the JSON representation of this example. The JSON - equivalent is always shown as a singleton map, which is how it will appear when the layout is used +

Example input: an example of a typical element for which this layout is appropriate, + shown as serialized XML.

+

Example output: the result of converting this example, shown as serialized JSON. The + result is always shown as a singleton map, which is how it will appear when the layout is used for the top-level elements supplied in the $elements argument; when used to convert a descendant element, the corresponding key-value pair may appear as part of a larger map, depending on the layout chosen for its parent element..

The fn:elements-to-maps function produces maps as its result, but it is convenient to illustrate the form of the map by showing the effect of serializing the map as JSON.

-

XSD conditions: the properties of the XSD type definition that cause this +

Mapping rules: The rules for mapping the XML element to an XDM map representation.

Mapping for nilled elements: special rules that apply to an @@ -7896,15 +7904,18 @@ return

by this mapping and what information is lost.

+

The rules for selecting the layout for a particular element are given later, + in .

+

Note that it is possible to use any layout for any element. Use of an inappropriate layout may result in information being discarded; but in some cases, discarding information may be the - desired outcome. In a few cases use of an inappropriate layout may lead to a dynamic error.

+ desired outcome.

Acknowledgements for this categorization: see . Although Goessner's categories have been used, the actual mappings vary from his proposal.

- + Layout: Empty Content
@@ -7918,14 +7929,14 @@ return
- + - + - +

Intended for XML elements that have no content and no attributes.

XML exampleExample input ]]>
JSON equivalentExample output { "hr": "" }
Mapping rules

The content is represented by the zero-length xs:string @@ -7951,8 +7962,8 @@ return which the JSON serialization method serializes as null. For example the result of converting the element <hr xsi:nil="true"/> becomes - { "hr": xs:QName("fn:null") } - is serialized as { "hr": null }.

+ { "hr": xs:QName("fn:null") }, which is serialized in JSON + as { "hr": null }.

@@ -7962,7 +7973,7 @@ return
Notes
- + Layout: Empty Content with Attributes @@ -7976,14 +7987,14 @@ return
- + - + - +

Intended for XML elements that have no content but may have attributes.

XML exampleExample input ]]>
JSON equivalentExample output { "hr": { "@class": "ccc", "@id": "zzz" } }
Mapping rules

The content is represented by a map containing one entry for each @@ -8021,7 +8032,7 @@ return
- + Layout: Simple Content @@ -8035,21 +8046,21 @@ return
- + - + - +

Intended for XML elements that have simple content and no attributes.

XML exampleExample input 2023-05-30]]>
JSON equivalentExample output { "date": "2023-05-30" }
Mapping rules

The element is atomized and the resulting atomized value is handled @@ -8071,15 +8082,16 @@ return
Notes

If any attributes are present, they are discarded. If the element has a type annotation that is a complex type with element-only content, atomization will fail and - a dynamic error occurs. In the case of mixed content, if child elements are present, - atomization means that they will not appear explicitly in the result.

+ the string value is used in its place. In the case of mixed content, + atomization produces essentially the same result as the string value, which + means that the internal structure is lost.

Comments and processing instructions in the content are discarded. Whitespace is retained.

- + Layout: Simple Content with Attributes @@ -8093,25 +8105,25 @@ return
- + - + - + -

Intended for XML elements that have simple content and (optionally) attributes.

XML exampleExample input 23.50]]>
JSON equivalentExample output { "price": { "@currency": "USD", "#content": 23.50 } }
Mapping rules

The content is represented by a map containing one entry for each - attribute in the XML element, plus an entry with key "#content" +

The element is represented by a map containing one entry for each + of its attributes, plus an entry with key "#content" representing the result of atomizing the element. The atomized value is handled as described in .

The rules for attribute names are @@ -8133,15 +8145,16 @@ return -
Notes

In the case of mixed content, if child elements are present, - atomization means that they will not appear in the result.

+

In the case of mixed content, + atomization produces essentially the same result as the string value, which + means that the internal structure is lost.

Comments and processing instructions in the content are discarded. Whitespace is retained.

- + Layout: Simple List @@ -8153,12 +8166,11 @@ return
- +
Usage

Intended for XML elements that act as wrappers for a list of child elements, - all having the same element name. Any attributes on either the wrapper element or - the wrapped elements will be discarded. + all having the same element name. The name of the child elements is not retained in the output.

XML example (1)Example input (1) 2023-03-20 2023-04-12 @@ -8166,11 +8178,11 @@ return ]]> - + - +
JSON equivalent (1)Example output (1) { "dates": [ "2023-03-20", "2023-04-12", "2023-05-30" ] }
XML example (2)Example intput (2) 20230320 20230412 @@ -8178,14 +8190,14 @@ return ]]> - + - +
JSON equivalent (2)Example output (2) { "dates": [ { "year": "2023", "month": "03", "day": "20" }, { "year": "2023", "month": "04", "day": "12" }, { "year": "2023", "month": "05", "day": "30" } ] }
Mapping rules

If the element has element children with names that are not all equal, or if it has non-whitespace text node children, then it is output - as if the mixed layout were chosen. This is fallback behavior for use + as if mixed layout were chosen (see ). + This is fallback behavior for use when this layout is chosen inappropriately.

In other cases, the content is represented by an array, whose members correspond one-to-one with the children of the element. @@ -8243,7 +8256,7 @@ return ]} ]]>--> - + Layout: List with Attributes
@@ -8256,10 +8269,10 @@ return
+ and the name of the child elements is retained in the output.

- +
Usage

Intended for XML elements that act as wrappers for a list of child elements, all having the same element name. The wrapper element may have attributes, - and the name of the child elements is retained in the JSON output.

XML example (1)Example input (1) 2023-03-20 2023-04-12 @@ -8267,11 +8280,11 @@ return ]]> - + - +
JSON equivalent (1)Example output (1) "dates": { "@id": "x", "date": ["2023-03-20", "2023-04-12", "2023-05-30"]}
XML example (2)Example input (2) 20230320 20230412 @@ -8279,7 +8292,7 @@ return ]]> - +
JSON equivalent (2)Example output (2) { "dates": { "@id": "x", "date": [ @@ -8288,7 +8301,7 @@ return { "year": "2023", "month": "05", "day": "30" } ] } } - +
Mapping rules

If the element has element children with names that are not all equal, or if it has non-whitespace text node children, then it is output - as if mixed layout were chosen. This is fallback behavior for use + as if mixed layout were chosen (see . + This is fallback behavior for use when this layout is chosen inappropriately.

In other cases, the content is represented by a map containing one entry for each @@ -8323,10 +8337,11 @@ return - + For example the element ]]> + becomes {"dates": { "@id": "x", "#content": xs:QName("fn:null") } }.

@@ -8348,7 +8363,7 @@ return
Mapping for nilled elements

The array is replaced by the atomic item xs:QName("fn:null"), +

The array-valued entry in the result is replaced by the entry + "#content": xs:QName("fn:null"), which serializes to the JSON value null. - For example - {"dates": { "@id": "x", "date": xs:QName("fn:null") } }.

Notes
] ]]>--> - + Layout: Record
@@ -8365,7 +8380,7 @@ return
The element may or may not have attributes.

- +
XML exampleExample input (1) 1984-03-20 Germany @@ -8373,10 +8388,35 @@ return ]]> - - + + + + + + + + + +
JSON equivalent{ "employee": { "@id": "x", "date-of-birth": "1984-03-20", "location": "Germany", "position": "Janitor" } }Example output (1) +{ "employee": { "@id": "x", + "date-of-birth": "1984-03-20", + "location": "Germany", + "position": "Janitor" + } +}
Example input (2) + 1984-03-20 + Germany + Janitor + Gardener +]]>
Example output (2) +{ "employee": { "@id": "x", + "date-of-birth": "1984-03-20", + "location": "Germany", + "position": [ "Janitor", "Gardener" ] + } +}
Mapping rules

If the element has non-whitespace text node children, then it is output - as if mixed layout were chosen. This is fallback behavior for use + as if mixed layout were chosen (see ). + This is fallback behavior for use when this layout is chosen inappropriately.

In other cases, the content is represented by a map containing one entry for each @@ -8427,16 +8468,13 @@ return
Notes

Although this layout is intended primarily for elements whose children are unordered and uniquely named, it is also viable to use it in cases where elements can repeat, so - long as order relative to other elements is not significant. Indeed, - with XSD 1.1, a complex type defined using - xs:all can allow elements to appear more than once, and this will cause - this layout to be selected.

+ long as order relative to other elements is not significant.

Comments and processing instructions in the content are discarded.

- + Layout: Sequence @@ -8452,7 +8490,7 @@ return
The element may or may not have attributes.

- +
XML exampleExample input Introduction

Lorem ipsum.

@@ -8460,7 +8498,7 @@ return ]]> - +
JSON equivalentExample output { "section": [ { "@id": "x" }, { "head": "Introduction" }, @@ -8468,7 +8506,7 @@ return { "p": "Dolor sit amet" } ] } - + - + @@ -8500,7 +8537,7 @@ return
Mapping rules

The mapping rules are identical to the rules for the mixed layout (see - ) except that whitespace-only text nodes + ) except that whitespace-only text nodes are discarded.

Mapping for nilled elements

A nilled element is indicated by a property value of xs:QName("fn:null") in place - of the array. - For example, "section": xs:QName("fn:null"). - In JSON this is serialized as null.

A nilled element is indicated by including an additional map + { "#content" : xs:QName("fn:null")} in the array, after + any attributes.

Notes
- + Layout: Mixed @@ -8511,15 +8548,16 @@ return
- - + - +
Usage

Intended for XML elements that contain mixed content. +

Intended for XML elements that contain mixed content (that is, elements + that contain both child elements and child text nodes, intermingled). The element may or may not have attributes.

XML exampleExample input This is a fine mess!]]>
JSON equivalentExample output { "para": [ { "@id": "x" }, "This is a ", @@ -8527,7 +8565,7 @@ return "mess!" ] } - +
Mapping rules

The content is represented by an XDM array containing one entry for each @@ -8571,16 +8609,19 @@ return - +
Mapping for nilled elements

A nilled element is indicated by a property value of xs:QName("fn:null") in place - of the array. - For example, "para": xs:QName("fn:null"). - In JSON this is serialized as null.

A nilled element is indicated by including an additional map + { "#content" : xs:QName("fn:null")} in the array, after + any attributes. + For example, ]]> + becomes {"para": [ { "id": "p2" }, { "#content": xs:QName("fn:null") } ] }. + In JSON the value xs:QName("fn:null") + is serialized as null.

- + Layout: Serialized XML

Serialized layout allows an element node to be represented as lexical XML, contained within a map.

@@ -8598,14 +8639,14 @@ return textual content to be output as serialized XML.

- + - + - +
XML exampleExample input That was awesome

]]>
JSON equivalentExample output That was awesome

" }]]>
Mapping rules

The element node is serialized as if by the fn:serialize @@ -8632,9 +8673,9 @@ return - + @@ -8642,7 +8683,194 @@ return
Mapping for nilled elements

A nilled element is indicated by a property value of xs:QName("fn:null") - For example, "p": xs:QName("fn:null"). - In JSON this is serialized as null.

A nilled element is represented using its normal XML serialization, + that is, the output serialization includes the attribute xsi:nil="true", + together with a declaration of the xsi namespace prefix.

- + + + + Selecting an Element Layout +

The various layouts available for elements are described in . + This section defines the rules for selecting an element layout for a given element $E. + The rules are applied in order.

+ + +

If an explicit layout is given for the element name of $E in the + options argument of the fn:elements-to-maps function call, then that layout is used.

+

Let $elements be the value of the first argument to the + fn:elements-to-maps function call.

+

If the uniform option is true, then let $EE be + the set of all elements with the same name as $E, specifically + $elements/descendant-or-self::*[node-name(.) eq node-name($E)].

+

If the uniform option is false, then let $EE be $E.

+

Let T be the type identified by the type annotation of $E.

+

If T is xs:untyped or xs:anyType, then:

+ + +

If empty($EE/(* | text()) (that is, if there + are no child elements or text nodes) then:

+ +

If empty($EE/@*) (that is, if there + are no attributes) then empty: see .

+

Otherwise empty-plus: see .

+
+
+ +

If empty($EE/*) (that is, if there are no child elements) then:

+ +

If empty($EE/@*) (that is, if there + are no attributes) then simple: see .

+

Otherwise simple-plus: see .

+
+
+ +

If empty($EE/text()[normalize-space()]) (that is, there are no text node + children other than whitespace), then:

+ + +

If all-equal($EE/*/node-name()) and exists($EE/*[2]) + (that is, if all child elements have the same name, and at least one element has multiple child + elements), then:

+ +

If empty($EE/@*) (that is, if there + are no attributes) then list: see .

+

Otherwise list-plus: see .

+
+
+ +

If every $e in $EE satisfies all-different($e/*/node-name()) + (that is, the child elements are uniquely named among their siblings), + then record: see .

+
+ +

Otherwise, sequence: : see .

+
+
+
+ +

Otherwise, mixed: : see .

+
+
+
+ +

Otherwise (for an element $E that is schema-validated with + type annotation T):

+

This section uses the notation {prop} to refer to properties + of schema components, as defined in . The schema component model + from XSD 1.1 is used; when XSD 1.0 is used for validation, some properties + such as {open content} will inevitably be absent.

+ + +

Let zeroLength(ST) be true for a simple type ST + if any of the following conditions is true:

+ + +

ST.{variety} = list, and ST.{facets} includes + a length or maxLength facet whose value is 0 (zero).

+
+ +

ST.{variety} = atomic, and ST.{facets} includes + a length or maxLength facet whose value is 0 (zero).

+
+ +

ST.{variety} = atomic, and ST.{facets} includes + an enumeration facet constraining the value to be zero-length.

+
+ +

ST.{variety} = atomic, and ST.{facets} includes + a pattern facet with the value "" (a zero-length string).

+
+
+
+ +

If T is a simple type:

+ + +

If zeroLength(T), then empty: see .

+
+ +

Otherwise, simple: see .

+
+
+
+ +

Otherwise (if T is a complex type):

+ + +

Let $noAttributes be true if + T.{attribute uses} is empty and T.{attribute wildcard} + is absent.

+
+ +

If T.{content type}.{variety} = empty, then:

+ +

If $noAttributes then empty: see .

+

Otherwise, empty-plus: see .

+
+
+ +

If T.{content type}.{variety} = simple + (a complex type with simple content), then:

+ +

Let ST be T.{content type}.{simple type definition} + (the corresponding simple type).

+
+ +

If zeroLength(ST), then:

+ +

If $noAttributes then empty: see .

+

Otherwise, empty-plus: see .

+
+
+ +

Otherwise:

+ +

If $noAttributes then simple: see .

+

Otherwise, simple-plus: see .

+
+
+
+
+ +

If T.{content type}.{variety} = element-only (a complex type with + an element-only content model):

+ +

Let $noWildcards be true if T.{content type}.{open content} + is absent, and T.{content type}.{particle}, expanded recursively, contains + no wildcard term.

+

Let $childCardinalities be a set of (xs:QName, + xs:double) pairs + representing the expanded names of the element declaration terms within + T.{content type}.{particle}, + expanded recursively, and for each one, the maximum number of occurrences of elements + with that name, computed + using the value of the {maxOccurs} property of the particles at each level, taking the value + unbounded as positive infinity.

+ +

If $noWildcards is true, and if $childCardinalities + contains a single entry, and that entry has a cardinality greater than one, then:

+ +

If $noAttributes, then list: see .

+

Otherwise, list-plus: see .

+
+
+ +

If $noWildcards is true, and if every entry in $childCardinalities + has a cardinality of one, then record: see .

+
+ +

Otherwise, sequence: see .

+
+
+
+ +

Otherwise (when T.{content type}.{variety} = mixed), then mixed: see .

+
+
+
+
+
+
+
+ + Element and Attribute Names

The name-format option gives control over how element and attribute names are formatted. @@ -8694,8 +8922,7 @@ return

- - + @@ -8730,8 +8957,61 @@ return
subsequently serialized as JSON.

+ + Lost XDM Information + +

This section is non-normative. Its purpose is to explain what information available + in the XDM nodes supplied as input to the fn:elements-to-maps function + is missing from the output.

+ + +

Element and attribute names: If the chosen + name-format is default or eqname, + then local names and namespace URIs of elements and attributes are retained, + but namespace prefixes are lost. If the chosen name-format is + lexical, then prefixes are retained but namespace URIs are lost. + If the chosen name-format is local then only + local names are retained; namespace URIs and prefixes are lost.

+ +

In addition, element names are lost when the parent element is mapped + using list layout: see .

+ +

In-scope namespaces: All information about in-scope namespaces + (and in particular, bindings for namespaces that are declared but not used in element + and attribute names) is lost.

+ +

The xsi namespace: All attributes in the xsi + namespace (http://www.w3.org/2001/XMLSchema-instance) are lost, + except when xml layout is selected.

+ +

Comments and processing instructions: Comments and processing instructions + are lost except when they appear as children of elements that are mapped using the + mixed or xml layouts.

+ +

Text nodes: Text nodes, both whitespace and non-whitespace, + are lost except when they appear as children of elements that are mapped using the + simple, simple-plus, mixed, or + xml layouts, or when they appear as grandchildren of elements that are + mapped using the list or list-plus layouts.

+ +

Additional node properties: The values of the is-id, + is-idref, and is-nilled properties of a node are lost.

+ +

Type annotations: The values of type annotations on elements are lost. + Type annotations on atomized values of nodes, however, are retained.

+ +

Element and attribute nodes: The entire content of element and attribute nodes + is lost if their parent element is mapped using a layout unsuited to that kind of content, + for example if the layout empty or simple is selected for an element that + has attributes or element children.

+ +

Element order: The order of child elements is lost when + record layout is used.

+
+
+ - + Examples

The following examples show the effect of transforming some simple XML documents with default options, and then serializing the result as JSON with indent is set to true. @@ -8741,7 +9021,7 @@ return

- + @@ -8828,7 +9108,7 @@ return
XDM elementJSON equivalentJSON serialization of result
- + @@ -12375,7 +12655,8 @@ currently, Version 9.0.0. Part 2: Datatypes Second Edition, Oct. 28 2004. Available at: http://www.w3.org/TR/xmlschema-2/ - + + From a9bc4b4d53606a378d467918e8b49308757d6f61 Mon Sep 17 00:00:00 2001 From: Michael Kay Date: Fri, 29 Nov 2024 22:27:40 +0000 Subject: [PATCH 2/3] Update specifications/xpath-functions-40/src/xpath-functions.xml MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Christian GrĂ¼n --- specifications/xpath-functions-40/src/xpath-functions.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/specifications/xpath-functions-40/src/xpath-functions.xml b/specifications/xpath-functions-40/src/xpath-functions.xml index ead82289c..5286e2936 100644 --- a/specifications/xpath-functions-40/src/xpath-functions.xml +++ b/specifications/xpath-functions-40/src/xpath-functions.xml @@ -8182,7 +8182,7 @@ return
XDM elementJSON equivalentJSON serialization of result
- +
{ "dates": [ "2023-03-20", "2023-04-12", "2023-05-30" ] }
Example intput (2)Example input (2) 20230320 20230412 From 5386cf998a1a5db08eaa529ddb5ccaf01f295924 Mon Sep 17 00:00:00 2001 From: Michael Kay Date: Fri, 29 Nov 2024 22:59:57 +0000 Subject: [PATCH 3/3] Add support for disable-layouts option --- .../src/function-catalog.xml | 8 ++ .../src/xpath-functions.xml | 87 ++++++++++++------- 2 files changed, 62 insertions(+), 33 deletions(-) diff --git a/specifications/xpath-functions-40/src/function-catalog.xml b/specifications/xpath-functions-40/src/function-catalog.xml index 2f844c002..a93a4186f 100644 --- a/specifications/xpath-functions-40/src/function-catalog.xml +++ b/specifications/xpath-functions-40/src/function-catalog.xml @@ -25712,6 +25712,14 @@ return json-to-xml($json, $options)]]> "record", "sequence", "mixed", "xml")) map{} + + A list of layouts that will not be used for elements unless they are + selected explicitly. (Note that mixed and xml + layout cannot be disabled.) + enum("empty", "empty-plus", "simple", "simple-plus", "list", "list-plus", + "record", "sequence")* + () + diff --git a/specifications/xpath-functions-40/src/xpath-functions.xml b/specifications/xpath-functions-40/src/xpath-functions.xml index 5286e2936..4c81f6c00 100644 --- a/specifications/xpath-functions-40/src/xpath-functions.xml +++ b/specifications/xpath-functions-40/src/xpath-functions.xml @@ -7858,12 +7858,13 @@ return

If the uniform option is set to true, then the same layout will be used for all elements with a given name. This means that all elements need to be - examined before any element is converted. The layout chosen is the first one (in the order of - presentation in the following sections) whose match predicate matches every element with - the relevant name.

+ examined before any element is converted.

+

It is possible to disable some of the layouts so they will never be chosen by the automatic rules, + but only when explicitly selected.

+

The advantage of using schema information is that it gives a consistent representation for all elements of a particular type, even if they vary in content: for example if an element type allows optional attributes, the JSON representation will be consistent between those elements that have attributes and those @@ -7886,15 +7887,7 @@ return

on the layout chosen for its parent element..

The fn:elements-to-maps function produces maps as its result, but it is convenient to illustrate the form of the map by showing the effect of serializing the map as JSON.

- +

Mapping rules: The rules for mapping the XML element to an XDM map representation.

Mapping for nilled elements: special rules that apply to an @@ -8694,13 +8687,20 @@ return

If an explicit layout is given for the element name of $E in the options argument of the fn:elements-to-maps function call, then that layout is used.

+

Let $elements be the value of the first argument to the fn:elements-to-maps function call.

+ +

A layout is said to be disabled if its name is listed in the disable-layouts + option.

+

If the uniform option is true, then let $EE be the set of all elements with the same name as $E, specifically $elements/descendant-or-self::*[node-name(.) eq node-name($E)].

If the uniform option is false, then let $EE be $E.

+

Let T be the type identified by the type annotation of $E.

+

If T is xs:untyped or xs:anyType, then:

@@ -8708,16 +8708,20 @@ return
are no child elements or text nodes) then:

If empty($EE/@*) (that is, if there - are no attributes) then empty: see .

-

Otherwise empty-plus: see .

+ are no attributes) and if empty layout is not disabled, + then empty: see .

+

Otherwise, if empty-plus layout is not disabled, + then empty-plus: see .

If empty($EE/*) (that is, if there are no child elements) then:

If empty($EE/@*) (that is, if there - are no attributes) then simple: see .

-

Otherwise simple-plus: see .

+ are no attributes), and if simple layout is not disabled, + then simple: see .

+

Otherwise, if simple-plus layout is not disabled, + then simple-plus: see .

@@ -8730,22 +8734,26 @@ return
elements), then:

If empty($EE/@*) (that is, if there - are no attributes) then list: see .

-

Otherwise list-plus: see .

+ are no attributes), and if list layout is not disabled, + then list: see .

+

Otherwise, if list-plus layout is not disabled, + then list-plus: see .

If every $e in $EE satisfies all-different($e/*/node-name()) (that is, the child elements are uniquely named among their siblings), + and if record layout is not disabled, then record: see .

-

Otherwise, sequence: : see .

+

Otherwise, if sequence layout is not disabled, + then sequence: see .

-

Otherwise, mixed: : see .

+

Otherwise, mixed: see .

@@ -8783,10 +8791,12 @@ return

If T is a simple type:

-

If zeroLength(T), then empty: see .

+

If zeroLength(T), and if empty layout is + not disabled, then empty: see .

-

Otherwise, simple: see .

+

Otherwise, if simple layout is not disabled, then + simple: see .

@@ -8801,8 +8811,10 @@ return

If T.{content type}.{variety} = empty, then:

-

If $noAttributes then empty: see .

-

Otherwise, empty-plus: see .

+

If $noAttributes and if empty layout is not disabled, + then empty: see .

+

Otherwise, if empty-plus layout is not disabled, + then empty-plus: see .

@@ -8815,15 +8827,19 @@ return

If zeroLength(ST), then:

-

If $noAttributes then empty: see .

-

Otherwise, empty-plus: see .

+

If $noAttributes and if empty layout is + not disabled, then empty: see .

+

Otherwise, if empty-plus layout is not disabled, + then empty-plus: see .

Otherwise:

-

If $noAttributes then simple: see .

-

Otherwise, simple-plus: see .

+

If $noAttributes and if simple layout + is not disabled, then simple: see .

+

Otherwise, if simple-plus layout is not disabled, + then simple-plus: see .

@@ -8847,21 +8863,26 @@ return

If $noWildcards is true, and if $childCardinalities contains a single entry, and that entry has a cardinality greater than one, then:

-

If $noAttributes, then list: see .

-

Otherwise, list-plus: see .

+

If $noAttributes, and if list layout + is not disabled, then list: see .

+

Otherwise, if list-plus layout is not disabled, + then list-plus: see .

If $noWildcards is true, and if every entry in $childCardinalities - has a cardinality of one, then record: see .

+ has a cardinality of one, and if record layout is not disabled, + then record: see .

-

Otherwise, sequence: see .

+

Otherwise, if sequence layout is not disabled, + then sequence: see .

-

Otherwise (when T.{content type}.{variety} = mixed), then mixed: see .

+

Otherwise (that is, when T.{content type}.{variety} = mixed, or when all other + applicable layouts have been disabled), then mixed: see .