Skip to content

Commit

Permalink
Add support for disable-layouts option
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelhkay committed Nov 29, 2024
1 parent b15ad3c commit 0fa582a
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 33 deletions.
8 changes: 8 additions & 0 deletions specifications/xpath-functions-40/src/function-catalog.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25523,6 +25523,14 @@ return json-to-xml($json, $options)]]></eg>
"record", "sequence", "mixed", "xml"))</fos:type>
<fos:default>map{}</fos:default>
</fos:option>
<fos:option key="disable-layouts">
<fos:meaning>A list of layouts that will not be used for elements unless they are
selected explicitly. (Note that <code>mixed</code> and <code>xml</code>
layout cannot be disabled.)</fos:meaning>
<fos:type>enum("empty", "empty-plus", "simple", "simple-plus", "list", "list-plus",
"record", "sequence")*</fos:type>
<fos:default>()</fos:default>
</fos:option>
</fos:options>


Expand Down
87 changes: 54 additions & 33 deletions specifications/xpath-functions-40/src/xpath-functions.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7842,12 +7842,13 @@ return <table>
<item>
<p>If the <code>uniform</code> option is set to <code>true</code>, 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.</p>
examined before any element is converted.</p>
</item>
</ulist>

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

<p>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
Expand All @@ -7870,15 +7871,7 @@ return <table>
on the layout chosen for its parent element..</p>
<note><p>The <code>fn:elements-to-maps</code> 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.</p></note></item>
<!--<item><p><term>XSD conditions</term>: the properties of the XSD type definition that cause this
layout to be selected. The first layout (in the order they appear in this specification)
that meets these conditions will be chosen. Note that two elements with the same name may
have different XSD type definitions.</p></item>
<item><p><term>Match predicate</term>: an XPath 4.0 expression, to be evaluated with an element node
as the context item, whose effective boolean value indicates whether this layout is suited
to a particular element node. The first layout whose match predicate evaluates
to <code>true</code> will be chosen.</p>
</item>-->

<item><p><term>Mapping rules</term>: The rules for mapping the XML element to an XDM map
representation.</p></item>
<item><p><term>Mapping for nilled elements</term>: special rules that apply to an
Expand Down Expand Up @@ -8678,30 +8671,41 @@ return <table>
<olist>
<item><p>If an explicit layout is given for the element name of <code>$E</code> in the
options argument of the <code>fn:elements-to-maps</code> function call, then that layout is used.</p></item>

<item><p>Let <code>$elements</code> be the value of the first argument to the
<code>fn:elements-to-maps</code> function call.</p></item>

<item><p>A layout is said to be disabled if its name is listed in the <code>disable-layouts</code>
option.</p></item>

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

<item><p>Let <var>T</var> be the type identified by the type annotation of <code>$E</code>.</p></item>

<item><p>If <var>T</var> is <code>xs:untyped</code> or <code>xs:anyType</code>, then:</p>
<olist>
<item>
<p>If <code>empty($EE/(* | text())</code> (that is, if there
are no child elements or text nodes) then:</p>
<olist>
<item><p>If <code>empty($EE/@*)</code> (that is, if there
are no attributes) then <code>empty</code>: see <specref ref="id-empty-layout"/>.</p></item>
<item><p>Otherwise <code>empty-plus</code>: see <specref ref="id-empty-plus-layout"/>.</p></item>
are no attributes) and if <code>empty</code> layout is not disabled,
then <code>empty</code>: see <specref ref="id-empty-layout"/>.</p></item>
<item><p>Otherwise, if <code>empty-plus</code> layout is not disabled,
then <code>empty-plus</code>: see <specref ref="id-empty-plus-layout"/>.</p></item>
</olist>
</item>
<item>
<p>If <code>empty($EE/*)</code> (that is, if there are no child elements) then:</p>
<olist>
<item><p>If <code>empty($EE/@*)</code> (that is, if there
are no attributes) then <code>simple</code>: see <specref ref="id-simple-layout"/>.</p></item>
<item><p>Otherwise <code>simple-plus</code>: see <specref ref="id-simple-plus-layout"/>.</p></item>
are no attributes), and if <code>simple</code> layout is not disabled,
then <code>simple</code>: see <specref ref="id-simple-layout"/>.</p></item>
<item><p>Otherwise, if <code>simple-plus</code> layout is not disabled,
then <code>simple-plus</code>: see <specref ref="id-simple-plus-layout"/>.</p></item>
</olist>
</item>
<item>
Expand All @@ -8714,22 +8718,26 @@ return <table>
elements), then:</p>
<olist>
<item><p>If <code>empty($EE/@*)</code> (that is, if there
are no attributes) then <code>list</code>: see <specref ref="id-list-layout"/>.</p></item>
<item><p>Otherwise <code>list-plus</code>: see <specref ref="id-list-plus-layout"/>.</p></item>
are no attributes), and if <code>list</code> layout is not disabled,
then <code>list</code>: see <specref ref="id-list-layout"/>.</p></item>
<item><p>Otherwise, if <code>list-plus</code> layout is not disabled,
then <code>list-plus</code>: see <specref ref="id-list-plus-layout"/>.</p></item>
</olist>
</item>
<item>
<p>If <code>every $e in $EE satisfies all-different($e/*/node-name())</code>
(that is, the child elements are uniquely named among their siblings),
and if <code>record</code> layout is not disabled,
then <code>record</code>: see <specref ref="id-record-layout"/>.</p>
</item>
<item>
<p>Otherwise, <code>sequence</code>: : see <specref ref="id-sequence-layout"/>.</p>
<p>Otherwise, if <code>sequence</code> layout is not disabled,
then <code>sequence</code>: see <specref ref="id-sequence-layout"/>.</p>
</item>
</olist>
</item>
<item>
<p>Otherwise, <code>mixed</code>: : see <specref ref="id-mixed-layout"/>.</p>
<p>Otherwise, <code>mixed</code>: see <specref ref="id-mixed-layout"/>.</p>
</item>
</olist>
</item>
Expand Down Expand Up @@ -8767,10 +8775,12 @@ return <table>
<p>If <var>T</var> is a simple type:</p>
<olist>
<item>
<p>If <code>zeroLength(T)</code>, then <code>empty</code>: see <specref ref="id-empty-layout"/>.</p>
<p>If <code>zeroLength(T)</code>, and if <code>empty</code> layout is
not disabled, then <code>empty</code>: see <specref ref="id-empty-layout"/>.</p>
</item>
<item>
<p>Otherwise, <code>simple</code>: see <specref ref="id-simple-layout"/>.</p>
<p>Otherwise, if <code>simple</code> layout is not disabled, then
<code>simple</code>: see <specref ref="id-simple-layout"/>.</p>
</item>
</olist>
</item>
Expand All @@ -8785,8 +8795,10 @@ return <table>
<item>
<p>If <code>T.{content type}.{variety} = empty</code>, then:</p>
<olist>
<item><p>If <code>$noAttributes</code> then <code>empty</code>: see <specref ref="id-empty-layout"/>.</p></item>
<item><p>Otherwise, <code>empty-plus</code>: see <specref ref="id-empty-plus-layout"/>.</p></item>
<item><p>If <code>$noAttributes</code> and if <code>empty</code> layout is not disabled,
then <code>empty</code>: see <specref ref="id-empty-layout"/>.</p></item>
<item><p>Otherwise, if <code>empty-plus</code> layout is not disabled,
then <code>empty-plus</code>: see <specref ref="id-empty-plus-layout"/>.</p></item>
</olist>
</item>
<item>
Expand All @@ -8799,15 +8811,19 @@ return <table>
<item>
<p>If <code>zeroLength(ST)</code>, then:</p>
<olist>
<item><p>If <code>$noAttributes</code> then <code>empty</code>: see <specref ref="id-empty-layout"/>.</p></item>
<item><p>Otherwise, <code>empty-plus</code>: see <specref ref="id-empty-plus-layout"/>.</p></item>
<item><p>If <code>$noAttributes</code> and if <code>empty</code> layout is
not disabled, then <code>empty</code>: see <specref ref="id-empty-layout"/>.</p></item>
<item><p>Otherwise, if <code>empty-plus</code> layout is not disabled,
then <code>empty-plus</code>: see <specref ref="id-empty-plus-layout"/>.</p></item>
</olist>
</item>
<item>
<p>Otherwise:</p>
<olist>
<item><p>If <code>$noAttributes</code> then <code>simple</code>: see <specref ref="id-simple-layout"/>.</p></item>
<item><p>Otherwise, <code>simple-plus</code>: see <specref ref="id-simple-plus-layout"/>.</p></item>
<item><p>If <code>$noAttributes</code> and if <code>simple</code> layout
is not disabled, then <code>simple</code>: see <specref ref="id-simple-layout"/>.</p></item>
<item><p>Otherwise, if <code>simple-plus</code> layout is not disabled,
then <code>simple-plus</code>: see <specref ref="id-simple-plus-layout"/>.</p></item>
</olist>
</item>
</olist>
Expand All @@ -8831,21 +8847,26 @@ return <table>
<p>If <code>$noWildcards</code> is true, and if <code>$childCardinalities</code>
contains a single entry, and that entry has a cardinality greater than one, then:</p>
<olist>
<item><p>If <code>$noAttributes</code>, then <code>list</code>: see <specref ref="id-list-layout"/>.</p></item>
<item><p>Otherwise, <code>list-plus</code>: see <specref ref="id-list-plus-layout"/>.</p></item>
<item><p>If <code>$noAttributes</code>, and if <code>list</code> layout
is not disabled, then <code>list</code>: see <specref ref="id-list-layout"/>.</p></item>
<item><p>Otherwise, if <code>list-plus</code> layout is not disabled,
then <code>list-plus</code>: see <specref ref="id-list-plus-layout"/>.</p></item>
</olist>
</item>
<item>
<p>If <code>$noWildcards</code> is true, and if every entry in <code>$childCardinalities</code>
has a cardinality of one, then <code>record</code>: see <specref ref="id-record-layout"/>.</p>
has a cardinality of one, and if <code>record</code> layout is not disabled,
then <code>record</code>: see <specref ref="id-record-layout"/>.</p>
</item>
<item>
<p>Otherwise, <code>sequence</code>: see <specref ref="id-sequence-layout"/>.</p>
<p>Otherwise, if <code>sequence</code> layout is not disabled,
then <code>sequence</code>: see <specref ref="id-sequence-layout"/>.</p>
</item>
</olist>
</item>
<item>
<p>Otherwise (when <code>T.{content type}.{variety} = mixed</code>), then <code>mixed</code>: see <specref ref="id-mixed-layout"/>.</p>
<p>Otherwise (that is, when <code>T.{content type}.{variety} = mixed</code>, or when all other
applicable layouts have been disabled), then <code>mixed</code>: see <specref ref="id-mixed-layout"/>.</p>
</item>
</olist>
</item>
Expand Down

0 comments on commit 0fa582a

Please sign in to comment.