Join GitHub today
Different error conditions for XPath expressions #796
Currently we have:
To my reading this means, that
is not an error (XD0008) because no context item is expected, but
will raise XD0005 even though the context item is not referred.
I fail to see the reason for this difference and think we should remove it.
Did I miss anything?
Those seem like near enough the same error that we don't need two error codes.
I have a marginal preference for the error not being dependent on whether or not the context item is actually referenced,.
In other words, I think both of the examples you give above should raise the error.
If we say it's ok to have a sequence as long as the context item isn't referenced, I think that introduces a usability problem: I have a pipeline that's been working fine for ages, I make a one character change to some expression and now it fails; I think that's confusing. It also introduces an implementation challenge since it means the processor has to analyze the expression and determine whether or not the context item is referenced which, in the face of conditional expressions, could be quite difficult to determine.
Actually I do not like our solution. Consider this example from the test-suite (ab-declare-step-011.xml)
This pipeline raises errors in two positions  and  because in both cases a sequence appears as context item. So one has to add an explicit
I think this is a usability problem.
Still sure you want the change?
May be we should try another approach: We could say, that XProc provides a context item for an XPath expression if and only if there is exactly one document provided. If there is no document or more than one document the context item is undefined.
In all cases where the XPath expression does not depend on the context item, this solution is fine and you get the result you would have expected. (Without adding extra p:sink or p:empty to your pipelines)
In the case where the XPath expression depends on the context item and you provide one XProc document every is fine too.
If the XPath expression depends on the context item and you provide none, you get an error as before. The only new thing is, that if XPath depends on the context item and you provide a sequence, you get an error from the underlying XPath implementation (err:XPDY0002) because the context item is absent.
To make this more transparent to pipeline authors we might say that an XProc processor is required to catch this error and produce an XDxxxx saying "This Xpath expression needs a context item, but you provided either none or a sequence".
Will that work out?