Re: [xsl] XPath is a composable language ... does that mean I can create an XPath expression for a then-clause and simply plug it into an if-then-else?

Subject: Re: [xsl] XPath is a composable language ... does that mean I can create an XPath expression for a then-clause and simply plug it into an if-then-else?
From: "Michael Kay michaelkay90@xxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Sun, 4 Dec 2022 17:26:12 -0000
Yes. "Composable" essentially means that expressions are built up from other
expressions, and where there is a slot for an expression, you can use any
expression you like. Of course there are some caveats: operator precedence
rules mean you might need to use parentheses, and type checking rules mean you
need to use an expression that delivers values of the right type. There might
be the odd exception (XPath 2.0 had an ugly rule that the first argument of
xs:QName had to be a string literal) but they are few and far between.

Michael Kay
Saxonica

> On 4 Dec 2022, at 17:11, Roger L Costello costello@xxxxxxxxx
<xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> wrote:
>
> Hi Folks,
>
> I have this English sentence:
>
> if the machine = "Intel 386 or later processors and compatible processors"
then ... else ... .
>
> I deliberately elided the then-clause and the else-clause.
>
> I need to turn that English sentence into XPath. I created this XPath:
>
> if (/Windows_Executable_File/Headers/File_Header/Machine = "Intel 386 or
later processors and compatible processors")
> then
>    ...
> else
>    ...
>
> Next, I created an XPath expression for the then-clause. I created the XPath
independent of its enveloping if-then-else. Let me denote the XPath expression
I created as: then-clause-XPath.
>
> I did the same for the else-clause.
>
> I then plugged then-clause-XPath and else-clause-XPath into the
if-then-else:
>
> if (/Windows_Executable_File/Headers/File_Header/Machine = "Intel 386 or
later processors and compatible processors")
> then
>    then-clause-XPath
> else
>    else-clause-XPath
>
> The XPath 3.0 specification says this:
>
>      XPath 3.0 is a composable language
>
> Does "composable language" mean I can do as I describe above and the result
will be a valid XPath expression?
>
> That is, can I develop an XPath expression for the then-clause completely
independent of its enveloping if-then-else and then simply plug the XPath into
the if-then-else? Ditto for the else-clause? Does "composable language" mean I
can do this kind of thing?
>
> /Roger

Current Thread