<?xml-stylesheet type="text/xsl" href="/style/testcase.xsl"?>
<t:test xmlns:t="http://xproc.org/ns/testsuite"
        xmlns:p="http://www.w3.org/ns/xproc"
        xmlns:c="http://www.w3.org/ns/xproc-step"
        xmlns:err="http://www.w3.org/ns/xproc-error">
  <t:title>Test viewport #005</t:title>
  
  <t:description xmlns="http://www.w3.org/1999/xhtml">
    <p>Test <code>p:viewport</code> with <code>p:iteration-position()</code> and <code>p:iteration-size()</code>.</p>
  </t:description>

  <t:input port="source">
    <doc>
      <para>Some paragraph.</para>
      <para>Some paragraph.</para>
      <para>Some paragraph.</para>
      <para>
        <para>Nested paragraph.</para>
      </para>
    </doc>
  </t:input>

  <t:pipeline>
    <p:pipeline version='1.0'>
      <p:viewport match="para" name="viewport">

        <p:choose name="choose">
          <p:when test="p:iteration-position() = 1">
            <p:identity>
              <p:input port="source">
                <p:inline><first/></p:inline>
                <p:pipe step="viewport" port="current"/>
              </p:input>
            </p:identity>
          </p:when>
          <p:when test="p:iteration-position() = p:iteration-size()">
            <p:identity>
              <p:input port="source">
                <p:pipe step="viewport" port="current"/>
                <p:inline><last/></p:inline>
              </p:input>
            </p:identity>
          </p:when>
          <p:otherwise>
            <p:identity/>
          </p:otherwise>
        </p:choose>

      </p:viewport>

    </p:pipeline>
  </t:pipeline>
  
  <t:output port="result">
    <doc>
      <first/><para>Some paragraph.</para>
      <para>Some paragraph.</para>
      <para>Some paragraph.</para>
      <para>
        <para>Nested paragraph.</para>
      </para><last/>
    </doc>
  </t:output>
</t:test>

