ACTION-1986 - Investigate dealing with excess namespace nodes in section 3.2 the instance element

All,

As discussed during our November 12 call [1]:

- One way (and the way I prefer) to look at the issue is to deal with
namespaces when the data model is created rather than at submission
time.
- The issue arises only when "the initial instance data is given by
inline content".

The current text is pretty clear that all namespaces which are in
scope on the <xf:instance> element are copied over to the data model:

    "If the initial instance data is given by inline content, then
instance data is obtained by first creating a detached copy of the
inline content (including namespaces inherited from the enveloping
ancestors), then creating an XPath data model over the detached copy.
The detached copy must consist of content that would be well-formed
XML if it existed in a separate document. Note that this restricts the
element content of instance to a single child element."

One possibility would be to:

- remove the text "including namespaces inherited from the enveloping ancestors"
- add the following text:

    "Namespace nodes in scope on the enclosing <xf:instance> are not
copied to the detached copy, except namespace nodes which map prefixes
which are in use by elements or attributes contained within the data
model."

The principles are as follows:

- copy the minimum amount of namespace nodes
- only copy namespace nodes to the root element
- following XSLT, only consider element and attribute names (other
uses of namespaces, e.g. in attribute values, are not guessed)
- if users actually need more namespaces in scope, they place it on
the root element

This means that simple copy/paste of XML content under <xf:instance> will work.

Here are a few examples:

<!-- Example 1: No namespaces copied -->
<xh:html
    xmlns:xh="http://www.w3.org/1999/xhtml"
    xmlns:xf="http://www.w3.org/2002/xforms"
    xmlns:foo="http://example.org/foo"
    xmlns:bar="http://example.org/bar">
    <xh:head>
        <xf:model>
            <xf:instance>
                <form>
                    <first-name/>
                </form>
            </xf:instance>
        </xf:model>
    </xh:head>
</xh:html>

<!-- Resulting data model -->
<form>
    <first-name/>
</form>

<!-- Example 2: Namespaces in use are copied -->
<xh:html
    xmlns:xh="http://www.w3.org/1999/xhtml"
    xmlns:xf="http://www.w3.org/2002/xforms"
    xmlns:foo="http://example.org/foo"
    xmlns:bar="http://example.org/bar">
    <xh:head>
        <xf:model>
            <xf:instance>
                <form>
                    <foo:first-name/>
                    <last-name bar:baz=""/>
                </form>
            </xf:instance>
        </xf:model>
    </xh:head>
</xh:html>

<!-- Resulting data model -->
<form xmlns:foo="http://example.org/foo"
      xmlns:bar="http://example.org/bar">
    <foo:first-name/>
    <last-name bar:baz=""/>
</form>

<!-- Example 3: Shadowed namespace prefix is not considered in use -->
<xh:html
    xmlns:xh="http://www.w3.org/1999/xhtml"
    xmlns:xf="http://www.w3.org/2002/xforms"
    xmlns:foo="http://example.org/foo"
    xmlns:bar="http://example.org/bar">
    <xh:head>
        <xf:model>
            <xf:instance>
                <form>
                    <foo:bar xmlns:foo="http://dummy.org/foo"/>
                </form>
            </xf:instance>
        </xf:model>
    </xh:head>
</xh:html>

<!-- Resulting data model -->
<form>
    <foo:bar xmlns:foo="http://dummy.org/foo"/>
</form>

<!-- Example 4: Namespace prefixes not used in element and attribute
names are not considered in use -->
<xh:html
    xmlns:xh="http://www.w3.org/1999/xhtml"
    xmlns:xf="http://www.w3.org/2002/xforms"
    xmlns:foo="http://example.org/foo"
    xmlns:bar="http://example.org/bar">
    <xh:head>
        <xf:model>
            <xf:instance>
                <form xmlns:baz="http://example.org/baz">
                    <expression value="foo:a/bar:b/baz:c"/>
                </form>
            </xf:instance>
        </xf:model>
    </xh:head>
</xh:html>

<form xmlns:baz="http://example.org/baz">
    <expression value="foo:a/bar:b/baz:c"/>
</form>

<!-- Example 5: User can work around this by placing namespace
declarations on root element  -->
<xh:html
    xmlns:xh="http://www.w3.org/1999/xhtml"
    xmlns:xf="http://www.w3.org/2002/xforms"
    xmlns:foo="http://example.org/foo"
    xmlns:bar="http://example.org/bar">
    <xh:head>
        <xf:model>
            <xf:instance>
                <form
                    xmlns:foo="http://example.org/foo"
                    xmlns:bar="http://example.org/bar"
                    xmlns:baz="http://example.org/baz">
                    <expression value="foo:a/bar:b/baz:c"/>
                </form>
            </xf:instance>
        </xf:model>
    </xh:head>
</xh:html>

<form
    xmlns:foo="http://example.org/foo"
    xmlns:bar="http://example.org/bar"
    xmlns:baz="http://example.org/baz">
    <expression value="foo:a/bar:b/baz:c"/>
</form>

This change can be done in two ways:

1. In a backward-incompatible way, whereby we change the default behavior.
2.In a backward-compatible way, where an attribute is needed to obtain
the new behavior:

<xf:instance copy-namespaces="false">
  ...
</xf:instance>

Thoughts welcome,

-Erik

[1] http://www.w3.org/2014/11/12-forms-minutes.html
[2] http://www.w3.org/TR/xslt-30/#element-copy

Received on Wednesday, 3 December 2014 02:16:15 UTC