Re: <p:xquery> with inline query?

David Birnbaum <djbpitt@gmail.com> writes:
> It raises XD0030 with the message "No proper query document found: substring(.,2)".

Try:

  <p:inline content-type="text/plain">substring(.,2)</p:inline>

If you don’t specify a content type, the content is treated as XML. The p:xquery step has special rules regarding XML input and I expect that “no proper query document” is trying to tell you that the input doesn’t conform to expectations.

My implementation doesn’t do much better with the error here:

Fatal err:XD0030 at file://…/pipe.xpl:15:15
Step failed: “No root”.

> 1. What would be a clean, idiomatic way of applying an arbitrary XPath function to a plain-text
> document as part of an XProc 3 pipeline?

I wrote a cx:xpath extension step to do this, but if you take XQuery as a rough approximation of XPath, I believe that fixing the content type would be enough. Here’s a five minute effort at constructing an XPath step:

  <p:declare-step type="ex:xpath">
    <p:input port="source" sequence="true"/>
    <p:output port="result"/>
    <p:option name="expr" as="xs:string" required="true"/>

    <p:xquery>
      <p:with-input port="query">
        <p:inline content-type="text/plain">{$expr}</p:inline>
      </p:with-input>
    </p:xquery>
  </p:declare-step>

Then you can write:

  <p:if test="starts-with(., '&#xfeff;')">
    <ex:xpath expr="substring(.,2)"/>
  </p:if>

> 2. Where in the spec or online tutorials or elsewhere should I have been able to find an answer to
> this question?

I’m compiling a list of “easy mistakes to make”. I’ll add this one :-)

                                        Be seeing you,
                                          norm

--
Norm Tovey-Walsh <ndw@nwalsh.com>
https://norm.tovey-walsh.com/

> In the end, we will remember not the words of our enemies, but the
> silence of our friends.--Martin Luther King Jr.

Received on Wednesday, 22 January 2025 08:26:12 UTC