JSON merge 019(AB)

Tests mixing all possible documents

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:json-merge key="concat('label-',$p:index)">
      <p:with-input expand-text="false">
         <p:inline content-type="application/json">{"key1" : "value1"}</p:inline>
         <p:inline content-type="application/json">[1, 2]</p:inline>
         <p:inline content-type="text/plain">This is a text document.</p:inline>
         <p:inline>
            <xml/>
         </p:inline>
         <p:inline content-type="text/html">
            <html/>
         </p:inline>
      </p:with-input>
   </p:json-merge>
   <p:cast-content-type content-type="application/xml"/>
</p:declare-step>

Result

<map xmlns="http://www.w3.org/2005/xpath-functions"
     xmlns:t="http://xproc.org/ns/testsuite/3.0">
   <string key="key1">value1</string>
   <array key="label-2">
      <number>1</number>
      <number>2</number>
   </array>
   <string key="label-3">This is a text document.</string>
   <string key="label-4"><xml/></string>
   <string key="label-5"><html/></string>
</map>

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="fn"
         uri="http://www.w3.org/2005/xpath-functions"/>
   <s:pattern>
      <s:rule context="/">
         <s:assert test="fn:map">The document node is not 'fn:map'.</s:assert>
         <s:assert test="count(fn:map/*)=5">Document does not have five children.</s:assert>
      </s:rule>
      <s:rule context="/fn:map/*[1]">
         <s:assert test="local-name(.)='string'">Local name of child element 1 is not 'string'.</s:assert>
         <s:assert test="./@key='key1'">Child element 1 does not have @key with 'key1'.</s:assert>
         <s:assert test="./text()='value1'">Child element 1 does not have text child 'value1'.</s:assert>
      </s:rule>
      <s:rule context="/fn:map/*[2]">
         <s:assert test="local-name(.)='array'">Local name of child element 2 is not 'array'.</s:assert>
         <s:assert test="./@key='label-2'">Child element 2 does not have @key with 'label-2'.</s:assert>
         <s:assert test="./fn:number[1]='1'">Child element 2 does not have a child 'fn:number' with '1'.</s:assert>
         <s:assert test="./fn:number[2]='2'">Child element 2 does not have a child 'fn:number' with '2'.</s:assert>
      </s:rule>
      <s:rule context="/fn:map/*[3]">
         <s:assert test="local-name(.)='string'">Local name of child element 3 is not 'string'.</s:assert>
         <s:assert test="./@key='label-3'">Child element 3 does not have @key with 'label-3'.</s:assert>
         <s:assert test="./text()='This is a text document.'">Child element 3 does not have text child with 'This is a text document'.</s:assert>
      </s:rule>
      <s:rule context="/fn:map/*[4]">
         <s:assert test="local-name(.)='string'">Local name of child element 4 is not 'string'.</s:assert>
         <s:assert test="./@key='label-4'">Child element 4 does not have @key with 'label-4'.</s:assert>
         <s:assert test="./text()='<xml/>'">Child element 4 does not have text child with '<xml/>'.</s:assert>
      </s:rule>
      <s:rule context="/fn:map/*[5]">
         <s:assert test="local-name(.)='string'">Local name of child element 5 is not 'string'.</s:assert>
         <s:assert test="./@key='label-5'">Child element 5 does not have @key with 'label-5'.</s:assert>
         <s:assert test="starts-with(./text(), '<html')">Child element 5 does not have text child with '<html/>'.</s:assert>
      </s:rule>
   </s:pattern>
</s:schema>

Revision history

10 Jun 2021, Achim Berndzen
Added attribute 'queryBinding' to schematron's schema.
13 Oct 2019, Achim Berndzen
Added tests for p:json-merge