AB for-each 003

Test p:for-eachp:iteration-size() and p:iteration-position()(ported from 1.0-testsuite/for-each-003)

Test is expected to pass.

Input: source

<doc xmlns:t="http://xproc.org/ns/testsuite/3.0">
   <title>Some title</title>
   <para>Paragraph 1.</para>
   <para>Paragraph 2.</para>
   <para>Paragraph 3.</para>
</doc>

The pipeline

<p:declare-step xmlns:p="http://www.w3.org/ns/xproc"
                xmlns:t="http://xproc.org/ns/testsuite/3.0" version="3.0">
   <p:input port="source"/>
   <p:output port="result"/>
   <p:for-each name="for">
      <p:with-input select="//para"/>
      <p:choose>
         <p:when test="p:iteration-position() = 1">
            <p:identity>
               <p:with-input port="source">
                  <p:inline>
                     <first/>
                  </p:inline>
                  <p:pipe step="for" port="current"/>
               </p:with-input>
            </p:identity>
         </p:when>
         <p:when test="p:iteration-position() = p:iteration-size()">
            <p:identity>
               <p:with-input port="source">
                  <p:pipe step="for" port="current"/>
                  <p:inline>
                     <last/>
                  </p:inline>
               </p:with-input>
            </p:identity>
         </p:when>
         <p:otherwise>
            <p:identity/>
         </p:otherwise>
      </p:choose>
   </p:for-each>
   <p:wrap-sequence wrapper="wrapper"/>
</p:declare-step>

Result

<wrapper xmlns:t="http://xproc.org/ns/testsuite/3.0">
   <first/>
   <para>Paragraph 1.</para>
   <para>Paragraph 2.</para>
   <para>Paragraph 3.</para>
   <last/>
</wrapper>

Schematron checks

<s:schema xmlns="http://www.w3.org/1999/xhtml"
          xmlns:s="http://purl.oclc.org/dsdl/schematron" xmlns:t="http://xproc.org/ns/testsuite/3.0"
          queryBinding="xslt2">
   <s:pattern>
      <s:rule context="/">
         <s:assert test="wrapper">The document root is not wrapper.</s:assert>
         <s:assert test="wrapper/*[1]/name()='first'">First child of wrapper is not 'first'.</s:assert>
         <s:assert test="wrapper/*[2]/name()='para'">Second child of wrapper is not 'para'.</s:assert>
         <s:assert test="wrapper/*[3]/name()='para'">Third child of wrapper is not 'para'.</s:assert>
         <s:assert test="wrapper/*[4]/name()='para'">Fourth child of wrapper is not 'para'.</s:assert>
         <s:assert test="wrapper/*[5]/name()='last'">Fifth child of wrapper is not 'last'.</s:assert>
         <s:assert test="count(wrapper/*)=5">Wrapper does not have five children.</s:assert>
         <s:assert test="wrapper/para[1]/text()='Paragraph 1.'">Content of first para child is not 'Paragraph 1.'</s:assert>
         <s:assert test="wrapper/para[2]/text()='Paragraph 2.'">Content of second para child is not 'Paragraph 2.'</s:assert>
         <s:assert test="wrapper/para[3]/text()='Paragraph 3.'">Content of thrid para child is not 'Paragraph 3.'</s:assert>
      </s:rule>
   </s:pattern>
</s:schema>

Revision history

10 Jun 2021, Achim Berndzen
Added attribute 'queryBinding' to schematron's schema.
16 Mar 2019, Achim Berndzen
Fixed test by getting patterns right.
08 Jan 2019, Achim Berndzen
Initial test