Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Context item always refers to document set? #48

Open
xatapult opened this issue Jun 19, 2024 · 0 comments
Open

Context item always refers to document set? #48

xatapult opened this issue Jun 19, 2024 · 0 comments

Comments

@xatapult
Copy link
Contributor

xatapult commented Jun 19, 2024

Currently the context item only exists when a single document is flowing through the pipeline. Assume this is an XML document:

<p:variable name="doc" as="document-node()" select="."/>

But when a sequence of document is possible and there is no or multiple document(s), there is no context item.

That leads to some weird coding problems. For instance, I want to catch the results on the error port of p:os-exec. What I intuitively do is:

<p:variable name="error-message" as="xs:string" select="string(.)" pipe="error@..."/>

But this doesn't fly because when there is no error, there is no context item... Why? I have to resort to clumsy looking solutions like:

<p:variable name="error-message" as="xs:string" select="string(collection()[1])" collection="true" pipe="error@..."/>

So can't we define that the context item always exists and is always the sequence of documents that's flowing through?

  • No document? Empty sequence
  • Single document? Just as it is now
  • Multiple documents? Sequence of item() representing the documents (in the right order!). So document-node() for documents, maps or arrays for JSON, etc.

In retrospect, isn't the whole thing with making sequence of documents special (the use of the collection attribute) an XProc/XPath 1.0 left-over?

It would also solve #22. You could simply write count(.) to get the number of documents and exists(.) or empty(.) to check whether a document is there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant