label-elements 005 (AB)

Testing p:label-elements.

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" version="3.0">
   <p:output port="result"/>
   <p:input port="source">
      <doc>
         <div>
            <p>Some para.</p>
            <p>Some other para.</p>
         </div>
      </doc>
   </p:input>
   <p:label-elements xmlns:test="http://test.com"
                     label='concat("_foo_", $p:index, "_bar_")' attribute="test:pid"
                     replace="true" match="p"/>
</p:declare-step>

Result

<doc xmlns:t="http://xproc.org/ns/testsuite/3.0">
   <div>
      <p xmlns:test="http://test.com"
         test:pid="_foo_1_bar_">Some para.</p>
      <p xmlns:test="http://test.com"
         test:pid="_foo_2_bar_">Some other para.</p>
   </div>
</doc>

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 uri="http://test.com" prefix="test"/>
   <s:pattern>
      <s:rule context="/">
         <s:assert test="doc">The document root is not 'doc'</s:assert>
         <s:assert test="count(doc/@*)=0">The document root should not have an attribute.</s:assert>
         <s:assert test="doc/div">The root element does not have a child 'div'.</s:assert>
         <s:assert test="count(doc/*)=1">The root element should have only one child.</s:assert>
         <s:assert test="count(doc/div/@*)=0">Element 'div' should not have an attribute.</s:assert>
         <s:assert test="count(doc/div/*)=2">Element 'div' should have two children.</s:assert>
         <s:assert test="doc/div/p[1]/@test:pid">Element 'p[1]' does not have an attribute 'test:pid'.</s:assert>
         <s:assert test="count(doc/div/p[1]/@*)=1">Element 'p[1]' should habe exactly one attribute.</s:assert>
         <s:assert test="doc/div/p[1]/@test:pid='_foo_1_bar_'">Value of p[1]/test:pid is not '_foo_1_bar_'.</s:assert>
         <s:assert test="doc/div/p[1]/text()='Some para.'">Text value of p[1] is not 'Some para.'</s:assert>
         <s:assert test="doc/div/p[2]/@test:pid">Element 'p[2]' does not have an attribute 'test:pid'.</s:assert>
         <s:assert test="count(doc/div/p[2]/@*)=1">Element 'p[2]' should habe exactly one attribute.</s:assert>
         <s:assert test="doc/div/p[2]/@test:pid='_foo_2_bar_'">Value of p[2]/test:pid is not '_foo_2_bar_'.</s:assert>
         <s:assert test="doc/div/p[2]/text()='Some other para.'">Text value of p[2] is not 'Some other para.'</s:assert>
      </s:rule>
   </s:pattern>
</s:schema>

Revision history

10 Jun 2021, Achim Berndzen
Added attribute 'queryBinding' to schematron's schema.
04 May 2019, Achim Berndzen
Ported test from 1.0 test suite