xsl-list
[Top] [All Lists]

Re: [xsl] XSLT 2.0 courses?

2020-09-21 06:18:39
In its original sense, bzw. (beziehungsweise) means 'respectively', but yes, it has assumed the additional meaning of something like 'or', 'or else', or 'or rather'.

https://en.m.wiktionary.org/wiki/beziehungsweise

'or else' is appropriate for the operator, but it might be a nightmare grammar-wise (XPath grammar, not English grammar).


On 21.09.2020 13:01, Michael Kay mike(_at_)saxonica(_dot_)com wrote:
Perhaps we should call it "bzw" - a German word that is sadly missing from English.

Mike

On 21 Sep 2020, at 11:58, Imsieke, Gerrit, le-tex gerrit(_dot_)imsieke(_at_)le-tex(_dot_)de <mailto:gerrit(_dot_)imsieke(_at_)le-tex(_dot_)de> <xsl-list-service(_at_)lists(_dot_)mulberrytech(_dot_)com <mailto:xsl-list-service(_at_)lists(_dot_)mulberrytech(_dot_)com>> wrote:

Thank you, this is convincing.

One might consider naming the 'otherwise' operator 'alternatively', but this is not the hill I'm going to die on.

Gerrit

On 21.09.2020 12:53, Michael Kay mike(_at_)saxonica(_dot_)com <mailto:mike(_at_)saxonica(_dot_)com> wrote:
Well, I thought about using EBV, so it means (if ($a) then $a else $b), but zero is falsey, so you get surprises with, for example
@price * (1 + (@VAT_Rate otherwise 0.2))
which potentially gives the wrong answer if @VAT_Rate is present but zero. And it also gets complicated with atomization: if the attribute is present but set to a zero length string, which way do you go?
Michael Kay
Saxonica
On 21 Sep 2020, at 11:21, Imsieke, Gerrit, le-tex gerrit(_dot_)imsieke(_at_)le-tex(_dot_)de <mailto:gerrit(_dot_)imsieke(_at_)le-tex(_dot_)de> <mailto:gerrit(_dot_)imsieke(_at_)le-tex(_dot_)de <mailto:gerrit(_dot_)imsieke(_at_)le-tex(_dot_)de>> <xsl-list-service(_at_)lists(_dot_)mulberrytech(_dot_)com <mailto:xsl-list-service(_at_)lists(_dot_)mulberrytech(_dot_)com> <mailto:xsl-list-service(_at_)lists(_dot_)mulberrytech(_dot_)com <mailto:xsl-list-service(_at_)lists(_dot_)mulberrytech(_dot_)com>>> wrote:

If the boolean variable $a is false() instead of an empty sequence,

$a otherwise $b

will return false(). This is the specified behaviour, but I find it a bit counterintuitive. I have a slight preference for the otherwise operator to return $b if $a is false().

Have you thought about defining the otherwise operator as "it returns $a unless it's an empty sequence or a boolean value equal to false(), in which case it returns $b"? I'm not sure which one will seem more natural to most users.

Gerrit

On 21.09.2020 10:46, Michael Kay mike(_at_)saxonica(_dot_)com <mailto:mike(_at_)saxonica(_dot_)com> <mailto:mike(_at_)saxonica(_dot_)com <mailto:mike(_at_)saxonica(_dot_)com>> wrote:
I've been proposing ($a otherwise $b) to meet this requirement: it returns $a unless it's an empty sequence, in which case it returns $b.
For example @price - (@discount otherwise 0)
It's actually implemented in Saxon 10 if you switch syntax extensions on.
Michael Kay
Saxonica
On 21 Sep 2020, at 02:34, Pieter Lamers pieter(_dot_)lamers(_at_)benjamins(_dot_)nl <mailto:pieter(_dot_)lamers(_at_)benjamins(_dot_)nl> <mailto:pieter(_dot_)lamers(_at_)benjamins(_dot_)nl <mailto:pieter(_dot_)lamers(_at_)benjamins(_dot_)nl>> <mailto:pieter(_dot_)lamers(_at_)benjamins(_dot_)nl <mailto:pieter(_dot_)lamers(_at_)benjamins(_dot_)nl> <mailto:pieter(_dot_)lamers(_at_)benjamins(_dot_)nl <mailto:pieter(_dot_)lamers(_at_)benjamins(_dot_)nl>>> <xsl-list-service(_at_)lists(_dot_)mulberrytech(_dot_)com <mailto:xsl-list-service(_at_)lists(_dot_)mulberrytech(_dot_)com> <mailto:xsl-list-service(_at_)lists(_dot_)mulberrytech(_dot_)com <mailto:xsl-list-service(_at_)lists(_dot_)mulberrytech(_dot_)com>> <mailto:xsl-list-service(_at_)lists(_dot_)mulberrytech(_dot_)com <mailto:xsl-list-service(_at_)lists(_dot_)mulberrytech(_dot_)com> <mailto:xsl-list-service(_at_)lists(_dot_)mulberrytech(_dot_)com <mailto:xsl-list-service(_at_)lists(_dot_)mulberrytech(_dot_)com>>>> wrote:

Hi,

An avid user of ($a, $b)[1] myself, which winks at TransactSQL ISNULL($a, $b) and MySQL IFNULL($a, $b), I do have to remind myself that $a has to be a single item for the /if/else /shortcut to work.

So, in

let $a := ('one','two','three')
let $b := ('none')

return ($a, $b)[1] will return just the first item in the sequence, 'one', and not 'one','two','three', which might be what you want to achieve in this quasi shorthanded /if/else /construction.

Not that you wouldn't know, Liam, just as a heads up to some others in this audience who might not.

Best,
Pieter

On 19/09/2020 01:54, Liam R. E. Quin liam(_at_)fromoldbooks(_dot_)org <mailto:liam(_at_)fromoldbooks(_dot_)org> <mailto:liam(_at_)fromoldbooks(_dot_)org <mailto:liam(_at_)fromoldbooks(_dot_)org>> wrote:
On Fri, 2020-09-18 at 19:31 +0000, Wendell Piezwapiez(_at_)wendellpiez(_dot_)com <mailto:Piezwapiez(_at_)wendellpiez(_dot_)com> <mailto:Piezwapiez(_at_)wendellpiez(_dot_)com <mailto:Piezwapiez(_at_)wendellpiez(_dot_)com>>
wrote:
Hi,

In addition to Liam's list I think there are a couple more vital
features
one needs to get a taste of in XSLT 2.0 or XSLT 3.0, if one has been
subsisting on an XSLT 1.0 diet:

* <xsl:for-each-group> and its uses
* temporary trees -
* regex support in functions and xsl:analyze-string
* tunnel parameters?
Yeah, those are all huge, although i think easier to learn than things
like ($a, 'none')[1], which are startling because XSLT 1 didn't have
sequences.

For those wondering, ($a, $b, $c, ...)[1] returns the first non-empty
non-false item out of $a, $b and $c, so it's a shortcut for
    <xsl:sequence select="if ($a) then $a else $b" />


On regular expressions - it's huge, but it's also dangerous, as e.g.
replace(price div 100, '\.\d*$', '') is not a good way to write
math:floor().

An XSLT-3-from-scratch course could easily take a full week and be
woefully incomplete. Or totally overwhelming. Or both.

On the other hand, i try & include "don't be afraid of the specs" in
the courses i teach, and then not cover every detail. So maybe it's
possible.

Liam

--~----------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
EasyUnsubscribe: http://lists.mulberrytech.com/unsub/xsl-list/1167547
or by email: xsl-list-unsub(_at_)lists(_dot_)mulberrytech(_dot_)com
--~--

<Prev in Thread] Current Thread [Next in Thread>