AB for-each 005

Test evaluation of variables in the context of a p:for-each (ported from 1.0-testsuite/for-each-005)

Test is expected to pass.

The pipeline

<p:declare-step xmlns:p="http://www.w3.org/ns/xproc"
                xmlns:t="http://xproc.org/ns/testsuite/3.0"
                xmlns:xs="http://www.w3.org/2001/XMLSchema" version="3.0">
   <p:output port="result"/>
   <p:input port="source">
      <p:inline>
         <doc>
            <para id="x1">Some paragraph.</para>
            <para id="x2">Some paragraph.</para>
            <para id="x3">Some paragraph.</para>
         </doc>
      </p:inline>
   </p:input>
   <p:for-each name="loop">
      <p:with-input select="/doc/para"/>
      <p:variable name="q" select="/para/@id"
                  as="xs:string">
         <p:pipe step="loop" port="current"/>
      </p:variable>
      <p:choose>
         <p:when test="$q = 'x2'">
            <p:identity/>
         </p:when>
         <p:otherwise>
            <p:identity>
               <p:with-input port="source">
                  <p:empty/>
               </p:with-input>
            </p:identity>
         </p:otherwise>
      </p:choose>
   </p:for-each>
   <p:wrap-sequence wrapper="newdoc"/>
</p:declare-step>

Result

<newdoc xmlns:t="http://xproc.org/ns/testsuite/3.0">
   <para xmlns:xs="http://www.w3.org/2001/XMLSchema"
         id="x2">Some paragraph.</para>
</newdoc>

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="newdoc">The document root is not 'newdoc'.</s:assert>
         <s:assert test="newdoc/para">The root element does not have a child 'para'</s:assert>
         <s:assert test="count(newdoc/para)=1">The root element does not have ONE child 'para'.</s:assert>
         <s:assert test="newdoc/para/@id='x2'">The para element with @id='x2' was not selected.</s:assert>
         <s:assert test="newdoc/para='Some paragraph.'">The content of para element is not 'Some pharagraph.'</s:assert>
      </s:rule>
   </s:pattern>
</s:schema>

Revision history

10 Jun 2021, Achim Berndzen
Added attribute 'queryBinding' to schematron's schema.
20 Jul 2019, Achim Berndzen
Fixed test by declaring xs-namespace.
09 Jan 2019, Achim Berndzen
Initial test