rdf-srx-002

Tests that cx:sparql can produce application/sparql-results+xml.

Test is expected to pass.

The pipeline

<p:declare-step xmlns:cx="http://xmlcalabash.com/ns/extensions"
                xmlns:p="http://www.w3.org/ns/xproc"
                xmlns:t="http://xproc.org/ns/testsuite/3.0" name="main" version="3.0"
                expand-text="false">
   <p:import href="https://xmlcalabash.com/ext/library/rdf.xpl"/>
   <p:output port="result"/>
   <cx:sparql content-type="application/sparql-results+xml">
      <p:with-input port="source"
                    href="../documents/address-book.rdf"/>
      <p:with-input port="query"
                    href="../documents/query2.rq"/>
   </cx:sparql>
</p:declare-step>

Result

<sparql xmlns="http://www.w3.org/2005/sparql-results#"
        xmlns:t="http://xproc.org/ns/testsuite/3.0">
   <head>
      <variable name="category"/>
      <variable name="name"/>
      <variable name="locality"/>
   </head>
   <results>
      <result>
         <binding name="name">
            <literal datatype="http://www.w3.org/2001/XMLSchema#string">Timo’s</literal>
         </binding>
         <binding name="category">
            <literal datatype="http://www.w3.org/2001/XMLSchema#string">Restaurants</literal>
         </binding>
         <binding name="locality">
            <literal datatype="http://www.w3.org/2001/XMLSchema#string">San Francisco</literal>
         </binding>
      </result>
      <result>
         <binding name="name">
            <literal datatype="http://www.w3.org/2001/XMLSchema#string">Tamarine Restaurant</literal>
         </binding>
         <binding name="category">
            <literal datatype="http://www.w3.org/2001/XMLSchema#string">Restaurants</literal>
         </binding>
         <binding name="locality">
            <literal datatype="http://www.w3.org/2001/XMLSchema#string">Palo Alto</literal>
         </binding>
      </result>
      <result>
         <binding name="name">
            <literal datatype="http://www.w3.org/2001/XMLSchema#string">Patina</literal>
         </binding>
         <binding name="category">
            <literal datatype="http://www.w3.org/2001/XMLSchema#string">Restaurants</literal>
         </binding>
         <binding name="locality">
            <literal datatype="http://www.w3.org/2001/XMLSchema#string">Los Angeles</literal>
         </binding>
      </result>
      <result>
         <binding name="name">
            <literal datatype="http://www.w3.org/2001/XMLSchema#string">Masa’s Restaurant</literal>
         </binding>
         <binding name="category">
            <literal datatype="http://www.w3.org/2001/XMLSchema#string">Restaurants</literal>
         </binding>
         <binding name="locality">
            <literal datatype="http://www.w3.org/2001/XMLSchema#string">San Francisco</literal>
         </binding>
      </result>
      <result>
         <binding name="name">
            <literal datatype="http://www.w3.org/2001/XMLSchema#string">Luka’s Taproom & Lounge</literal>
         </binding>
         <binding name="category">
            <literal datatype="http://www.w3.org/2001/XMLSchema#string">Restaurants</literal>
         </binding>
         <binding name="locality">
            <literal datatype="http://www.w3.org/2001/XMLSchema#string">Oakland</literal>
         </binding>
      </result>
      <result>
         <binding name="name">
            <literal datatype="http://www.w3.org/2001/XMLSchema#string">Le Papillon</literal>
         </binding>
         <binding name="category">
            <literal datatype="http://www.w3.org/2001/XMLSchema#string">Restaurants</literal>
         </binding>
         <binding name="locality">
            <literal datatype="http://www.w3.org/2001/XMLSchema#string">San Jose</literal>
         </binding>
      </result>
      <result>
         <binding name="name">
            <literal datatype="http://www.w3.org/2001/XMLSchema#string">Kabul Afghan Cuisine</literal>
         </binding>
         <binding name="category">
            <literal datatype="http://www.w3.org/2001/XMLSchema#string">Restaurants</literal>
         </binding>
         <binding name="locality">
            <literal datatype="http://www.w3.org/2001/XMLSchema#string">San Carlos</literal>
         </binding>
      </result>
      <result>
         <binding name="name">
            <literal datatype="http://www.w3.org/2001/XMLSchema#string">71 Saint Peter</literal>
         </binding>
         <binding name="category">
            <literal datatype="http://www.w3.org/2001/XMLSchema#string">Restaurants</literal>
         </binding>
         <binding name="locality">
            <literal datatype="http://www.w3.org/2001/XMLSchema#string">San Jose</literal>
         </binding>
      </result>
      <result>
         <binding name="name">
            <literal datatype="http://www.w3.org/2001/XMLSchema#string">À Côté</literal>
         </binding>
         <binding name="category">
            <literal datatype="http://www.w3.org/2001/XMLSchema#string">Restaurants</literal>
         </binding>
         <binding name="locality">
            <literal datatype="http://www.w3.org/2001/XMLSchema#string">Oakland</literal>
         </binding>
      </result>
      <result>
         <binding name="name">
            <literal datatype="http://www.w3.org/2001/XMLSchema#string">Amber Indian Restaurant</literal>
         </binding>
         <binding name="category">
            <literal datatype="http://www.w3.org/2001/XMLSchema#string">Restaurants</literal>
         </binding>
         <binding name="locality">
            <literal datatype="http://www.w3.org/2001/XMLSchema#string">Mountain View</literal>
         </binding>
      </result>
      <result>
         <binding name="name">
            <literal datatype="http://www.w3.org/2001/XMLSchema#string">Boulevard</literal>
         </binding>
         <binding name="category">
            <literal datatype="http://www.w3.org/2001/XMLSchema#string">Restaurants</literal>
         </binding>
         <binding name="locality">
            <literal datatype="http://www.w3.org/2001/XMLSchema#string">San Francisco</literal>
         </binding>
      </result>
      <result>
         <binding name="name">
            <literal datatype="http://www.w3.org/2001/XMLSchema#string">Charles Nob Hill</literal>
         </binding>
         <binding name="category">
            <literal datatype="http://www.w3.org/2001/XMLSchema#string">Restaurants</literal>
         </binding>
         <binding name="locality">
            <literal datatype="http://www.w3.org/2001/XMLSchema#string">San Francisco</literal>
         </binding>
      </result>
      <result>
         <binding name="name">
            <literal datatype="http://www.w3.org/2001/XMLSchema#string">El Farolito</literal>
         </binding>
         <binding name="category">
            <literal datatype="http://www.w3.org/2001/XMLSchema#string">Restaurants</literal>
         </binding>
         <binding name="locality">
            <literal datatype="http://www.w3.org/2001/XMLSchema#string">San Francisco</literal>
         </binding>
      </result>
   </results>
</sparql>

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="r"
         uri="http://www.w3.org/2005/sparql-results#"/>
   <s:pattern>
      <s:rule context="/">
         <s:assert test="r:sparql">The root is not r:sparql.</s:assert>
         <s:assert test="r:sparql/r:head">There is no r:head</s:assert>
         <s:assert test="r:sparql/r:results">There is no r:results</s:assert>
      </s:rule>
   </s:pattern>
   <s:pattern>
      <s:rule context="/r:sparql/r:head">
         <s:assert test="count(r:variable) = 3">Wrong number of columns</s:assert>
         <s:assert test="r:variable[@name = 'category']">No category.</s:assert>
         <s:assert test="r:variable[@name = 'name']">No name.</s:assert>
         <s:assert test="r:variable[@name = 'locality']">No locality.</s:assert>
      </s:rule>
   </s:pattern>
   <s:pattern>
      <s:rule context="/r:sparql/r:results">
         <s:assert test="count(r:result) = 13">Wrong number of results: <s:value-of select="count(r:result)"/>
         </s:assert>
         <s:assert test="r:result/r:binding[@name='name']/r:literal = 'Patina'">One of the expected results is missing.</s:assert>
      </s:rule>
   </s:pattern>
</s:schema>

Revision history

15 Feb 2025, Norm Tovey-Walsh
Created test.