This is a general sort of ISO issue, and I know it's potentially nightmarish. Xpath usefully has a function
format-date
which has mind boggling parameters that I'll work out from
https://www.w3.org/TR/xpath-functions-31/#rules-for-datetime-formatting
but the obvious issue is my weeks start on Saturday.
The short term solution is to add two days to the date, and then get the year, week, day number... this will at least make the weeks line up, and 90+% of the time they'll be correct, sadly it isn't just an edge case of the 1st/last week of the year, because if the 1st week number is wrong, then all the week numbers in that year will be wrong.
So, how do I get
weeknumber
weekdaynumber
weekyear
if my weeks start on a Saturday?
The documentation (somewhere) in https://www.w3.org/TR/xpath-functions-31/#rules-for-datetime-formatting says:
The language is used to select the appropriate language-dependent forms of:
names (for example, of months)
numbers expressed as words or as ordinals (twenty, 20th, twentieth)
hour convention (0-23 vs 1-24, 0-11 vs 1-12)
first day of week, first week of year
Where appropriate this choice may also take into account the value of the $place argument, though this should not be used to override the language or any sublanguage that is specified as part of the language argument.
So you should try to specify the language. Note that support for the variety of languages might differ based on the XSLT/XQuery/XPath processor version and edition (I think Saxon PE/EE integrate ICU to have much broader support than HE (based on the Java JRE libs) has).