Add-attribute-027 (AB)

Tests adding attribute at multiple levels

Test is expected to pass.

The pipeline

<p:declare-step xmlns:html="http://www.w3.org/1999/xhtml"
                xmlns:p="http://www.w3.org/ns/xproc"
                xmlns:t="http://xproc.org/ns/testsuite/3.0" version="3.0">
   <p:output port="result"/>
   <p:add-attribute match="//html:*"
                    attribute-value="html" attribute-name="class">
      <p:with-input>
         <html xmlns="http://www.w3.org/1999/xhtml">
            <body>
               <h1>Header</h1>
               <p>Some text with 
                        <em>emphazised</em> phrase.</p>
               <ul>
                  <li>item</li>
                  <li>
                     <p>item</p>
                  </li>
                  <li>
                     <p>
                        <b>bold</b>
                     </p>
                  </li>
               </ul>
            </body>
         </html>
      </p:with-input>
   </p:add-attribute>
</p:declare-step>

Result

<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:html="http://www.w3.org/1999/xhtml" xmlns:t="http://xproc.org/ns/testsuite/3.0"
      class="html">
   <body class="html">
      <h1 class="html">Header</h1>
      <p class="html">Some text with 
                        <em class="html">emphazised</em> phrase.</p>
      <ul class="html">
         <li class="html">item</li>
         <li class="html">
            <p class="html">item</p>
         </li>
         <li class="html">
            <p class="html">
               <b class="html">bold</b>
            </p>
         </li>
      </ul>
   </body>
</html>

Schematron checks

<s:schema xmlns:s="http://purl.oclc.org/dsdl/schematron"
          xmlns:t="http://xproc.org/ns/testsuite/3.0" queryBinding="xslt2">
   <s:ns prefix="html"
         uri="http://www.w3.org/1999/xhtml"/>
   <s:pattern>
      <s:rule context="/">
         <s:assert test="html:html">The document root is not "html:html".</s:assert>
         <s:assert test="html:html/@class='html'">Element "html:html" does not have @class='html'.</s:assert>
         <s:assert test="html:html/html:body/@class='html'">Element "html/body" does not have @class='html'.</s:assert>
         <s:assert test="html:html/html:body/html:h1/@class='html'">Element "html/body/h1" does not have @class='html'.</s:assert>
         <s:assert test="html:html/html:body/html:p/@class='html'">Element "html/body/p" does not have @class='html'.</s:assert>
         <s:assert test="html:html/html:body/html:p/html:em/@class='html'">Element "html/body/p/em" does not have @class='html'.</s:assert>
         <s:assert test="html:html/html:body/html:ul/@class='html'">Element "html/body/ul" does not have @class='html'.</s:assert>
         <s:assert test="html:html/html:body/html:ul/html:li/@class='html'">Element "html/body/ul/li" does not have @class='html'.</s:assert>
         <s:assert test="html:html/html:body/html:ul/html:li[2]/html:p/@class='html'">Element "html/body/ul/li[2]/p" does not have @class='html'.</s:assert>
         <s:assert test="html:html/html:body/html:ul/html:li[3]/html:p/@class='html'">Element "html/body/ul/li[3]/p" does not have @class='html'.</s:assert>
         <s:assert test="html:html/html:body/html:ul/html:li[3]/html:p//html:b/@class='html'">Element "html/body/ul/li[3]/p/b" does not have @class='html'.</s:assert>
      </s:rule>
   </s:pattern>
</s:schema>

Revision history

10 Jun 2021, Achim Berndzen
Added attribute 'queryBinding' to schematron's schema.
16 Feb 2019, Achim Berndzen
Added new tests for p:add-attribute.