<?xml version="1.0" encoding="utf-8"?>
<t:test xmlns:t="http://xproc.org/ns/testsuite/3.0"
        xml:base="/nw-viewport-003.xml"
        name="nw-viewport-003.xml"
        expected="pass">
   <t:info>
      <t:title>Viewport 003</t:title>
      <t:revision-history>
         <t:revision>
            <t:date>2021-06-10</t:date>
            <t:author>
               <t:name>Achim Berndzen</t:name>
            </t:author>
            <t:description xmlns="http://www.w3.org/1999/xhtml">
               <p>Added attribute 'queryBinding' to schematron's schema.</p>
            </t:description>
         </t:revision>
         <t:revision>
            <t:date>2019-09-07</t:date>
            <t:author>
               <t:name>Achim Berndzen</t:name>
            </t:author>
            <t:description xmlns="http://www.w3.org/1999/xhtml">
               <p>Fix test so it fails if there is no ex:p.</p>
            </t:description>
         </t:revision>
         <t:revision>
            <t:date>2019-07-08</t:date>
            <t:author initials="ndw">
               <t:name>Norman Walsh</t:name>
            </t:author>
            <t:description xmlns="http://www.w3.org/1999/xhtml">
               <p>Initial publication</p>
            </t:description>
         </t:revision>
      </t:revision-history>
   </t:info>
   <t:description xmlns="http://www.w3.org/1999/xhtml">
      <p>Test that the match attribute can be an AVT with a variable reference.</p>
   </t:description>
   <t:input port="source">
      <doc xmlns="http://example.com/sample">
         <title>Some Title</title>
         <p>A paragraph.</p>
         <note xml:id="note">
            <p>A paragraph in note.</p>
         </note>
      </doc>
   </t:input>
   <t:pipeline>
      <p:declare-step xmlns:ex="http://example.com/sample"
                      xmlns:p="http://www.w3.org/ns/xproc"
                      xmlns:xs="http://www.w3.org/2001/XMLSchema"
                      version="3.0">
         <p:output port="result"/>
         <p:input port="source"/>
         <p:variable name="gi" select="xs:QName('ex:p')"/>
         <p:viewport match="*[node-name(.) = $gi]">
            <p:add-attribute attribute-name="v" attribute-value="true" match="/*"/>
         </p:viewport>
      </p:declare-step>
   </t:pipeline>
   <t:schematron>
      <s:schema xmlns="http://www.w3.org/1999/xhtml"
                xmlns:s="http://purl.oclc.org/dsdl/schematron"
                queryBinding="xslt2">
         <s:ns prefix="ex" uri="http://example.com/sample"/>
         <s:pattern>
            <s:rule context="/">
               <s:assert test="ex:doc">The pipeline root is not “doc”.</s:assert>
               <s:assert test="count(ex:doc//ex:p)=2">The pipeline root does not have two descendants "ex:p".</s:assert>
            </s:rule>
            <s:rule context="ex:p">
               <s:assert test=".[@v='true']">The ‘p’ elements don’t have the correct ‘v’ attributes.</s:assert>
            </s:rule>
            <s:rule context="*[not(self::ex:p)]">
               <s:assert test=".[not(@v)]">The ‘v’ attribute appears on the wrong element(s).</s:assert>
            </s:rule>
         </s:pattern>
      </s:schema>
   </t:schematron>
   <t:result name="nw-viewport-003.xml">
      <doc xmlns="http://example.com/sample">
         <title>Some Title</title>
         <p v="true">A paragraph.</p>
         <note xml:id="note">
            <p v="true">A paragraph in note.</p>
         </note>
      </doc>
   </t:result>
</t:test>
