Features: polyglot

polyglot-005

Tests that the cx:javascript polyglot step returns a string.

Test is expected to pass.

The pipeline

<p:declare-step xmlns:cx="http://xmlcalabash.com/ns/extensions"
                xmlns:err="http://www.w3.org/ns/xproc-error" xmlns:p="http://www.w3.org/ns/xproc"
                xmlns:t="http://xproc.org/ns/testsuite/3.0" version="3.0">
   <p:import href="https://xmlcalabash.com/ext/library/polyglot.xpl"/>
   <p:output port="result"/>
   <cx:javascript parameters="map{'x': 7, 'y': 9, 'now': current-dateTime()}">
      <p:with-input>
         <doc>Test</doc>
      </p:with-input>
      <p:with-option name="args"
                     select="('a', 'b', 'c')"/>
      <p:with-input port="program">
         <p:inline content-type="text/plain"
                   expand-text="false">
`The product is ${x*y}`
          </p:inline>
      </p:with-input>
   </cx:javascript>
   <p:wrap-sequence wrapper="doc"/>
</p:declare-step>

Result

<doc xmlns:t="http://xproc.org/ns/testsuite/3.0">The product is 63</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 prefix="fn"
         uri="http://www.w3.org/2005/xpath-functions"/>
   <s:pattern>
      <s:rule context="/">
         <s:assert test="doc">The document element is wrong</s:assert>
         <s:assert test="contains(doc, 'product is 63')">The string is incorrect.</s:assert>
      </s:rule>
   </s:pattern>
</s:schema>

Revision history

03 Jan 2025, Norm Tovey-Walsh
Created test.