Re: [xsl] Does it make sense to collect elements with a certain value then assert that the elements I've collected have that certain value?

Subject: Re: [xsl] Does it make sense to collect elements with a certain value then assert that the elements I've collected have that certain value?
From: "Michael Kay michaelkay90@xxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Wed, 31 Jul 2024 16:06:43 -0000
> To my way of thinking, there is no benefit. I collected <row> elements with
a matching ARPT_IDENT, then the assert tests that the collected <row> elements
have a matching ARPT_IDENT. The assert seems
pointless/redundant/useless/wasteful. Am I missing something?
>

That's surely the whole point of asserts. You typically assert that
`exists($doc//title)` if (a) you are absolutely sure this is going to be true,
and (b) it's not immediately obvious to everyone that it will always be true.
An assert always asserts something that you are confident will be true, but
where your confidence is the result of some non-trivial reasoning process.
It's there for two reasons: (a) so that the computer can tell you if your
confidence turns out to be misplaced, and (b) so that readers of the code can
see what's going on without having to repeat your reasoning process.

Well, actually, there is another reason to use assertions, namely to test for
external conditions that you want to treat as fatal. For example the assertion
test="doc-available('input.xml')" is there not because you're certain it will
always be true, but because you want to abort processing if it isn't. But
assertions aren't actually the ideal mechanism for that, because they are
often switched off by default when running in production.

Michael Kay
Saxonica

Current Thread