Algorithm Polish (variable re-names, prose clean-up and clarifying notes here and there).
authortravil
Thu, 27 Mar 2014 00:15:34 -0700
changeset 42 fa768c710fba
parent 41 f9b5a818ef99
child 43 a702e4acefbf
Algorithm Polish (variable re-names, prose clean-up and clarifying notes here and there).
Also added two cases where the inherited namespace was not updated, and finally,
changed what value is passed recursively for "namespace" to the element's children.
(Missed that last part on the previous commit.)
index.html
--- a/index.html	Wed Mar 26 19:11:22 2014 -0700
+++ b/index.html	Thu Mar 27 00:15:34 2014 -0700
@@ -284,7 +284,7 @@
             <li>Return an <a title="concept-serialize-xml">XML serialization</a> of <var>node</var>
                 providing to the algorithm a <a title="concept-context-namespace">context namespace</a> 
                 <var>namespace</var>, a <a title="concept-namespace-prefix-map">namespace prefix map</a>
-                <var>prefixes</var>, and a <a title="concept-generated-prefix">generated namespace prefix index</a>
+                <var>prefix map</var>, and a <a title="concept-generated-prefix">generated namespace prefix index</a>
                 <var>prefix index</var>.
         </ol>
 
@@ -331,8 +331,8 @@
         <p>To produce an <dfn title="concept-serialize-xml">XML serialization</dfn> of a
             <a title="node" data-spec="DOM4" class="externalDFN">Node</a> <var>node</var> given a
             <a title="concept-context-namespace">context namespace</a> <var>namespace</var>, a
-            <a title="concept-namespace-prefix-map">namespace prefix map</a> <var>prefixes</var> and
-            a <a title="concept-generated-prefix">generated namespace prefix index</a> 
+            <a title="concept-namespace-prefix-map">namespace prefix map</a> <var>prefix map</var> and
+            a reference to a <a title="concept-generated-prefix">generated namespace prefix index</a> 
             <var>prefix index</var>, the user agent must run the appropriate steps, depending on 
             <var>node</var>'s interface:</p>
                 
@@ -342,25 +342,25 @@
                 <p>Run the following algorithm:
                 <ol>
                     <!-- "namespace" was passed via the caller, it's the default namespace scope -->
-                    <!-- "prefixes" was passed via the caller, it's the namespace->prefix map -->
+                    <!-- "prefix map" was passed via the caller, it's the namespace->prefix map -->
                     <!-- "prefix index" was passed via the caller, it's a number for generating prefixes if necessary -->
                     <li>Let <var>markup</var> be the string "<code>&lt;</code>" (U+003C LESS-THAN SIGN).
                     <li>Let <var>qualified name</var> be an empty string.
                     <li>Let a <var>skip end tag</var> flag have the value <code>false</code>.
                     <li>Let an <var>ignore namespace definition attribute</var> flag have the value <code>false</code>.
-                    <li>Let <var>map</var> be a copy of the <var>prefixes</var> <a 
+                    <li>Let <var>map</var> be a copy of the <var>prefix map</var> <a 
                         title="concept-namespace-prefix-map">namespace prefix map</a>.
                     <li>Let <var>element prefixes list</var> be an empty list. <span class="note">This list is 
                         local to each element. Its purpose is to ensure that there are no conflicting prefixes 
                         should a new namespace prefix attribute need to be generated.</span>
-                    <li>Let <var>ignore duplicate prefix attribute</var> be <code>null</code>.
+                    <li>Let <var>duplicate prefix definition</var> be <code>null</code>.
                     <li>Let <var>local default namespace</var> be the result of 
                         <a title="concept-record-namespace-info">recording the namespace information</a> for 
                         <var>node</var> given <var>map</var>, <var>element prefixes list</var>, and 
-                        <var>ignore duplicate prefix attribute</var>.
+                        <var>duplicate prefix definition</var>.
                     <p class="note">This above step will update the <var>map</var> with any found namespace prefix 
                         definitions, add the found prefix definitions to the <var>element prefixes list</var>, optionally 
-                        set the <var>ignore duplicate prefix attribute</var> value, and return a local default namespace 
+                        set the <var>duplicate prefix definition</var> value, and return a local default namespace 
                         value defined by a default namespace attribute if one exists. Otherwise it returns
                         <code>null</code>.</p>
                     <li>Let <var>inherited ns</var> be a copy of <var>namespace</var>.
@@ -376,6 +376,7 @@
                             <a title="dom-element-localname" data-spec="DOM4" class="externalDFN">localName</a>.
                         <li>Otherwise, let <var>qualified name</var> be the value of <var>node</var>'s 
                             <a title="dom-element-localname" data-spec="DOM4" class="externalDFN">localName</a>.
+                            <span class="note">The <var>node</var>'s prefix is always dropped.</span>
                         <li>Append the value of <var>qualified name</var> to <var>markup</var>.
                     </ol>
                     <li>Otherwise, <var>inherited ns</var> is not equal to <var>ns</var> (the <var>node</var>'s
@@ -394,13 +395,17 @@
                         <!-- Found a suitable prefix to use, either locally, or inherited through a parent node that 
                             matches the node's namespaceURI. This prefix will be used in serialization even if the node 
                             doesn't have a real prefix. -->
-                        <li>If <var>candidate prefix</var> is not <code>null</code>, then:
+                        <li>If <var>candidate prefix</var> is not <code>null</code> (a suitable namespace prefix is defined 
+                            which maps to <var>ns</var>), then:
                         <ol>
                             <li>Let <var>qualified name</var> be the concatenation of <var>candidate prefix</var>, 
-                            "<code>:</code>" (U+003A COLON), and <code><a title="dom-element-localname" data-spec="DOM4" 
-                            class="externalDFN">localName</a></code>.
-                            <span class="note">There exists on this <var>node</var> or the <var>node</var>'s ancestry a 
-                            namespace prefix definition that defines the <var>node</var>'s namespace.</span>
+                                "<code>:</code>" (U+003A COLON), and <code><a title="dom-element-localname" data-spec="DOM4" 
+                                class="externalDFN">localName</a></code>.
+                                <span class="note">There exists on this <var>node</var> or the <var>node</var>'s ancestry a 
+                                namespace prefix definition that defines the <var>node</var>'s namespace.</span>
+                            <li>If <var>local default namespace</var> is not <code>null</code> (there exists a locally-defined
+                                default namespace declaration attribute), then let <var>inherited ns</var> get the value of
+                                <var>ns</var>.
                             <li>Append the value of <var>qualified name</var> to <var>markup</var>.
                         </ol>
                         <!-- Now there's no existing namespace->prefix mapping to override; try to use a prefix: -->
@@ -419,7 +424,8 @@
                             of <var>prefix</var>, "<code>:</code>" (U+003A COLON), and 
                             <code><a title="dom-element-localname" data-spec="DOM4" class="externalDFN">localName</a></code>.
                             <li>Append the value of <var>qualified name</var> to <var>markup</var>.
-                            <li>Append the following to <var>markup</var>, in order:
+                            <li>Append the following to <var>markup</var>, in order: <span class="note">The following 
+                                serializes the new namespace/prefix association just added to the <var>map</var>.</span>
                             <ol>
                                 <li>"<code> </code>" (U+0020 SPACE);
                                 <li>the string "<code>xmlns:</code>";
@@ -438,10 +444,12 @@
                             <li>Set the <var>ignore namespace definition attribute</var> flag to <code>true</code>.
                             <li>Let <var>qualified name</var> be the <var>node</var>'s <code><a title="dom-element-localname" 
                                 data-spec="DOM4" class="externalDFN">localName</a></code>.
-                            <li>Update the value of <var>inherited ns</var> to be <var>ns</var>. <span class="note">The new
-                                default namespace will be used as the inherited namespace for this node's children.</span>
+                            <li>Let the value of <var>inherited ns</var> be <var>ns</var>. <span class="note">The new
+                                default namespace will be used in the serialization to define this <var>node</var>'s 
+                                namespace and act as the context namespace for its children.</span>
                             <li>Append the value of <var>qualified name</var> to <var>markup</var>.
-                            <li>Append the following to <var>markup</var>, in order:
+                            <li>Append the following to <var>markup</var>, in order: <span class="note">The following 
+                                serializes the new (or replacement) default namespace definition.</span>
                             <ol>
                                 <li>"<code> </code>" (U+0020 SPACE);
                                 <li>the string "<code>xmlns</code>";
@@ -453,17 +461,19 @@
                         </ol>
                         <!-- Finally, regardless of prefix, the node has a local default namespace that matches 'ns'.
                             So, we'll just use that and drop the prefix -->
-                        <li>Otherwise, let <var>qualified name</var> be the <var>node</var>'s
-                            <code><a title="dom-element-localname" data-spec="DOM4" class="externalDFN">localName</a></code>
-                            and append the value of <var>qualified name</var> to <var>markup</var>.
+                        <li>Otherwise, the <var>node</var> has a <var>local default namespace</var> that matches 
+                            <var>ns</var>. Let <var>qualified name</var> be the <var>node</var>'s
+                            <code><a title="dom-element-localname" data-spec="DOM4" class="externalDFN">localName</a></code>,
+                            let the value of <var>inherited ns</var> be <var>ns</var>, and append the value of 
+                            <var>qualified name</var> to <var>markup</var>.
                     </ol>
                     <li>Append to <var>markup</var> the result of the
                         <a title="concept-serialize-xml-attributes">XML serialization of <var>node</var>'s 
                         attributes</a> given the
                         <a title="concept-namespace-prefix-map">namespace prefix map</a> <var>map</var>,
                         the <a title="concept-generated-prefix">generated prefix index</a> <var>prefix index</var>, the 
-                        flag <var>ignore namespace definition attribute</var> and the value of <var>ignore duplicate 
-                        prefix attribute</var>.
+                        flag <var>ignore namespace definition attribute</var> and the value of <var>duplicate 
+                        prefix definition</var>.
                     <li>If <var>ns</var> is the <a title="html-ns">HTML namespace</a>,
                         and the <var>node</var>'s list of 
                         <a title="concept-tree-child" data-spec="DOM4" class="externalDFN">children</a>
@@ -503,10 +513,9 @@
                         the value of <var>markup</var> and skip the remaining steps. The 
                         <var>node</var> is a leaf-node.
                     <li>Append to <var>markup</var> the result of performing an 
-                        <a title="concept-serialize-xml">XML serialization</a> of each of 
-                        <var>node</var>'s
+                        <a title="concept-serialize-xml">XML serialization</a> of each of <var>node</var>'s
                         <a title="concept-tree-child" data-spec="DOM4" class="externalDFN">children</a>,
-                        in order, providing the value of <var>ns</var> for the <var>namespace</var> string,
+                        in order, providing the value of <var>inherited ns</var> for the <var>namespace</var>,
                         <var>map</var> for the <a title="concept-namespace-prefix-map">namespace prefix map</a>,
                         and <var>prefix index</var> for the 
                         <a title="concept-generated-prefix">generated namespace prefix index</a>.
@@ -531,8 +540,10 @@
                     <li>The string produced by an <a title="concept-serialize-xml">XML serialization</a>
                         of <var>node</var>'s 
                         <a title="dom-document-documentelement" data-spec="HTML5" class="externalDFN">documentElement</a>
-                        attribute, providing <code>null</code> as the <var>namespace</var>, <var>map</var>
-                        for <var>prefixes</var>, and <var>prefix index</var>. 
+                        attribute, given <code>null</code> as the <var>namespace</var>, the 
+                        <a title="concept-namespace-prefix-map">namespace prefix map</a> <var>prefix map</var>,
+                        and a reference to the <a title="concept-generated-prefix">generated namespace 
+                        prefix index</a> <var>prefix index</var>. 
                 </ol>
 
             <dt><code><a title="comment" data-spec="DOM4" class="externalDFN">Comment</a></code>
@@ -678,10 +689,10 @@
         <p>To <dfn title="concept-record-namespace-info">record the namespace information</dfn> for an 
             <a title="element" data-spec="DOM4" class="externalDFN">Element</a> <var>element</var>, given a 
             <a title="concept-namespace-prefix-map">namespace prefix map</a> <var>map</var>, an
-            <var>element prefixes list</var> (initially empty), and an <var>ignore duplicate prefix 
-            attribute</var> reference, the user agent must run the following steps:
+            <var>element prefixes list</var> (initially empty), and a <var>duplicate prefix 
+            definition</var> reference, the user agent must run the following steps:
         <ol>
-            <li>Let <var>found default namespace attr</var> be <code>null</code>.
+            <li>Let <var>default namespace attr value</var> be <code>null</code>.
             <li>For each <a title="concept-attribute" data-spec="DOM4" class="externalDFN">attribute</a>
                 <var>attr</var> in <var>element</var>'s
                 <a title="concept-element-attribute" data-spec="DOM4" class="externalDFN">attributes</a>,
@@ -702,7 +713,7 @@
                 <li>If the <var>attribute namespace</var> is the <a title="xmlns-ns">XMLNS namespace</a>, then:
                 <ol>
                     <li>If <var>attribute prefix</var> is <code>null</code>, then <var>attr</var> is a 
-                        default namespace declaration. Set the value of <var>found default namespace attr</var> to 
+                        default namespace declaration. Set the <var>default namespace attr value</var> to 
                         <var>attr</var>'s <a title="dom-attribute-value" data-spec="DOM4"
                         class="externalDFN">value</a> and stop running these steps, returning to the 
                         top of the loop to visit the next attribute.
@@ -715,8 +726,8 @@
                             <a title="dom-attribute-value" data-spec="DOM4" class="externalDFN">value</a>.
                         <li>If a key matching the value of <var>namespace definition</var> already exists in
                             <var>map</var>, and the key's value matches <var>prefix definition</var>, then 
-                            this is a duplicate namespace prefix definition. Set the value of <var>ignore duplicate 
-                            prefix attribute</var> to <var>prefix definition</var>.
+                            this is a duplicate namespace prefix definition. Set the value of <var>duplicate 
+                            prefix definition</var> to <var>prefix definition</var>.
                         <li>Otherwise, if the key matching the value of <var>namespace definition</var> already 
                             exists in <var>map</var>, but the key's value does not match <var>prefix definition</var>,
                             then update the key's value to be <var>prefix definition</var>.
@@ -727,12 +738,12 @@
                     </ol>
                 </ol>
             </ol>
-            <li>Return the value of <var>found default namespace attr</var>.
+            <li>Return the value of <var>default namespace attr value</var>.
         </ol>
         
         <p>To <dfn title="concept-generate-prefix">generate a prefix</dfn> given a 
             <a title="concept-namespace-prefix-map">namespace prefix map</a> <var>map</var>, a 
-            string <var>new namespace</var>, and a 
+            string <var>new namespace</var>, and a reference to a
             <a title="concept-generated-prefix">generated namespace prefix index</a> <var>prefix
             index</var>, the user agent must run the following steps:
         <ol>
@@ -748,8 +759,8 @@
             of an <a title="concept-element" data-spec="DOM4" class="externalDFN">Element</a>
             <var>element</var> together with a <a title="concept-namespace-prefix-map">namespace prefix 
             map</a> <var>map</var>, a <a title="concept-generated-prefix">generated prefix index</a> 
-            <var>prefix index</var>, a flag <var>ignore namespace definition attribute</var> and an
-            <var>ignore duplicate prefix attribute</var> value, is the result of the following algorithm:
+            <var>prefix index</var> reference, a flag <var>ignore namespace definition attribute</var> and a
+            <var>duplicate prefix definition</var> value, is the result of the following algorithm:
         <ol>
             <li>Let <var>result</var> be the empty string.
             <li>For each <a title="concept-attribute" data-spec="DOM4" class="externalDFN">attribute</a>
@@ -761,34 +772,34 @@
                     <a title="dom-attribute-namespaceuri" data-spec="DOM4" class="externalDFN">namespaceURI</a>
                     value.
                 <!-- Check for an unregistered attribute namespace, and if so, serialize a definition for it -->
-                <li>Let <var>namespace prefix</var> be the empty string.
+                <li>Let <var>candidate prefix</var> be <code>null</code>.
                 <li>If <var>attribute namespace</var> is not <code>null</code>, then run these sub-steps:
                 <ol>
-                    <li>If there exists a key in <var>map</var> that matches the value of <var>attribute 
-                        namespace</var>, then let <var>namespace prefix</var> be that key's value from the 
-                        <var>map</var>.
-                    <li>Otherwise, if the value of <var>attribute namespace</var> is the 
+                    <li>If the value of <var>attribute namespace</var> is the 
                         <a title="xmlns-ns">XMLNS namespace</a> and either the <var>attr</var>'s 
-                        <a title="dom-attribute-localname" data-spec="DOM4" class="externalDFN">localName</a>
-                        matches the string "<code>xmlns</code>" and the <var>ignore namespace definition 
+                        <a title="dom-attribute-prefix" data-spec="DOM4" class="externalDFN">prefix</a>
+                        is <code>null</code> and the <var>ignore namespace definition 
                         attribute</var> flag is <code>true</code> or the <var>attr</var>'s 
                         <a title="dom-attribute-prefix" data-spec="DOM4" class="externalDFN">prefix</a>
-                        matches the string "<code>xmlns</code>" and the <var>attr</var>'s 
+                        is not <code>null</code> and the <var>attr</var>'s 
                         <a title="concept-attribute-localname" data-spec="DOM4" class="externalDFN">localName</a>
-                        matches the value of <var>ignore duplicate prefix attribute</var>, then stop running 
-                        these steps, returning to the top of the loop to visit the next attribute.
+                        matches the value of <var>duplicate prefix definition</var>, then stop running 
+                        these steps and return to the loop to visit the next attribute.
+                    <li>Otherwise, if there exists a key in <var>map</var> that matches the value of <var>attribute 
+                        namespace</var>, then let <var>candidate prefix</var> be that key's value from the 
+                        <var>map</var>.
                     <li>Otherwise, there is no key matching <var>attribute namespace</var> in <var>map</var> and
                         the <var>attribute namespace</var> is not the <a title="xmlns-ns">XMLNS namespace</a>. 
                         Run these steps:
                     <ol>
-                        <li>Let <var>namespace prefix</var> be the result of 
+                        <li>Let <var>candidate prefix</var> be the result of 
                             <a title="concept-generate-prefix">generating a prefix</a> providing <var>map</var>, 
                             <var>attribute namespace</var>, and <var>prefix index</var> as input.
                         <li>Append the following to <var>result</var>:
                         <ol>
                             <li>"<code> </code>" (U+0020 SPACE);
                             <li>The string "<code>xmlns:</code>";
-                            <li>The value of <var>namespace prefix</var>;
+                            <li>The value of <var>candidate prefix</var>;
                             <li>"<code>="</code>" (U+003D EQUALS SIGN, U+0022 QUOTATION MARK);
                             <li>The result of <a title="concept-serialize-attr-value">serializing an attribute value</a> 
                         given <var>attribute namespace</var> as input;
@@ -798,8 +809,8 @@
                 </ol>
                 <!-- A namespace prefix has been set by this point if it needed to be set -->
                 <li>Append a "<code> </code>" (U+0020 SPACE) to <var>result</var>.
-                <li>If <var>namespace prefix</var> is not the empty string, then append to <var>result</var>
-                    the concatenation of <var>namespace prefix</var> with "<code>:</code>" (U+003A COLON).
+                <li>If <var>candidate prefix</var> is not <code>null</code>, then append to <var>result</var>
+                    the concatenation of <var>candidate prefix</var> with "<code>:</code>" (U+003A COLON).
                 <!-- Write out the standard attribute -->
                 <li>Append the following strings to <var>result</var>:
                 <ol>
@@ -818,7 +829,7 @@
         <p>To <dfn title="concept-serialize-attr-value">serialize an attribute value</dfn> given an 
             <var>attribute value</var>, the user agent must run the following steps:
         <ol>
-            <li>If the <var>attribute value</var> is <code>null</code>, then return the empty string.
+            <li>If <var>attribute value</var> is <code>null</code>, then return the empty string.
             <li>Otherwise, <var>attribute value</var> is a string. Return <var>attribute value</var>,
                 first replacing any occurrences of the following:
             <ol>