<?xml version="1.0" encoding="iso-8859-1"?>
<?xml-stylesheet href="test-to-html.xsl" type="text/xml"?>
<!--
 Copyright (c) 2003 World Wide Web Consortium,

 (Massachusetts Institute of Technology, European Research Consortium for
 Informatics and Mathematics, Keio University). All Rights Reserved. This
 work is distributed under the W3C(r) Software License [1] in the hope that
 it will be useful, but WITHOUT ANY WARRANTY; without even the implied
 warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

 [1] http://www.w3.org/Consortium/Legal/2002/copyright-software-20021231
-->

<!DOCTYPE test SYSTEM "dom3.dtd" [
  <!ENTITY % entities SYSTEM "dom3xpathents.ent">
  %entities;
]>
<test xmlns="&level3;" name="XPathResult_iteratorNext_ORDERED_NODE_ITERATOR_TYPE">
  <metadata>
    <title>XPathResult_iteratorNext_ORDERED_NODE_ITERATOR_TYPE</title>
    <creator>Bob Clary</creator>
    <description>
    Create an XPathResult ORDERED_NODE_ITERATOR_TYPE XPathResultType for 
    expression /staff/employee/employeeId/text() checking that:
    XPathResult.iteratorNext returns the nodes in document order,
    and that the correct number is returned.
    </description>
    <date qualifier="created">2003-12-02</date>
    <subject resource="&spec;#XPathResult-iteratorNext"/>
    <subject resource="&spec;#XPathResult"/>
    <subject resource="&spec;#XPathResultType"/>
    <subject resource="&spec;#XPathEvaluator-createNSResolver"/>
  </metadata>

  <!-- Standard Variables -->

  <var name="ANY_TYPE"                     type="short" value="0"/>
  <var name="NUMBER_TYPE"                  type="short" value="1"/>
  <var name="STRING_TYPE"                  type="short" value="2"/>
  <var name="BOOLEAN_TYPE"                 type="short" value="3"/>
  <var name="UNORDERED_NODE_ITERATOR_TYPE" type="short" value="4"/>
  <var name="ORDERED_NODE_ITERATOR_TYPE"   type="short" value="5"/>
  <var name="UNORDERED_NODE_SNAPSHOT_TYPE" type="short" value="6"/>
  <var name="ORDERED_NODE_SNAPSHOT_TYPE"   type="short" value="7"/>
  <var name="ANY_UNORDERED_NODE_TYPE"      type="short" value="8"/>
  <var name="FIRST_ORDERED_NODE_TYPE"      type="short" value="9"/>

  <var name="doc"                 type="Document" />
  <var name="resolver"            type="XPathNSResolver" />
  <var name="evaluator"           type="XPathEvaluator" />
  <var name="contextNode"         type="Node" />
  <var name="inresult"            type="XPathResult" isNull="true"/>
  <var name="outresult"           type="XPathResult" isNull="true"/>

  <!-- Inputs -->

  <var name="expression"  type="DOMString" value="&quot;/staff/employee/employeeId/text()&quot;"/>
  <var name="xpathType"  type="short"     value="ORDERED_NODE_ITERATOR_TYPE" />

  <!-- Test Variables -->

  <var name="outNode"       type="Node"/>
  <var name="index"       type="int"/>
  <var name="text"        type="DOMString" />

  <!-- Load Test Document -->

  <load var="doc" href="staff" willBeModified="false"/>

  <!-- Get XPathResult -->

  <createXPathEvaluator var="evaluator" document="doc"/>

  <createNSResolver obj="evaluator" var="resolver" nodeResolver="doc"/>

  <assign var="contextNode" value="doc"/>

  <evaluate obj="evaluator"
            var="outresult"
            expression="expression"
            contextNode="contextNode"
            resolver="resolver"
            type="xpathType"
            result="inresult"
            interface="XPathEvaluator"
            />

  <assign var="index"
          value="0"
	  />

  <iterateNext var="outNode" obj="outresult"/> 
  <while>
    <notNull obj="outNode"/>

    <data         obj="outNode"
                  interface="CharacterData"
                  var="text"
                  />

    <if><equals actual="index" expected="0" />

      <assertEquals id="first"
                    actual="text"
                    expected="&quot;EMP0001&quot;"
                    ignoreCase="false"
                    />
     </if>
                
    <if><equals actual="index" expected="1" />

      <assertEquals id="second"
                    actual="text"
                    expected="&quot;EMP0002&quot;"
                    ignoreCase="false"
                    />
     </if>
                
    <if><equals actual="index" expected="2" />

      <assertEquals id="third"
                    actual="text"
                    expected="&quot;EMP0003&quot;"
                    ignoreCase="false"
                    />
     </if>
                
    <if><equals actual="index" expected="3" />

      <assertEquals id="fourth"
                    actual="text"
                    expected="&quot;EMP0004&quot;"
                    ignoreCase="false"
                    />
     </if>

    <if><equals actual="index" expected="4" />

      <assertEquals id="fifth"
                    actual="text"
                    expected="&quot;EMP0005&quot;"
                    ignoreCase="false"
                    />
     </if>

    <increment var="index"
               value="1"
	       />

    <iterateNext var="outNode" obj="outresult"/> 

  </while>

  <assertEquals id="count"
              actual="index"
	      expected="5"
	      ignoreCase="false"
	      />
</test>
