-
Notifications
You must be signed in to change notification settings - Fork 15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fn:format-number: Specifying decimal format #340
Comments
Yes, the current mechanism is very clumsy. I think the original intent in XSLT 1.0 was probably to define presentation "at arm's length" so that the logic didn't need to change if the output format changed, but that can be achieved perfectly well by putting the options in a global variable. |
I think that language-specific default settings would be sensible:
As known from the other functions for formatting numbers and dates, it could be up to the implementation to decide which languages are supported. The defaults could be overwritten by custom decimal-format declarations in the prolog to ensure that a setting is applied, even if an implementation does not support it. |
I'm not convinced this would give good interoperability. Consider Arabic for example: should it default to using western or eastern decimal digits? Both are in widespread use, and the idea that everyone with a particular (country, language) combination uses the same conventions is fundamentally misguided. This doesn't matter too much if it merely affects the format of the output, but it does matter if it makes a picture string valid in one implementation and invalid in another. |
I agree, there are cases which are easier to handle and others are more sophisticated. I think the same is true for formatting integers and dates: The rules are rich and sophisticated, but for more advanced use cases (such as spelling out correct hiragana for numbers with Japanese counter words, or considering declension of numerals in Russian), you’ll be lost without writing custom code. With ICU and Java, it’s fairly straightforward to choose language-specific formatting rules. I haven’t checked if there are flags to e.g. control formatting for Arabic numbers, and it could be that ICU has really taken the wrong path. From a German perspective, though, it’s restrictive that an implementation cannot provide sane defaults for Non-English users. This is how ICU formats integers with different locales:
Code: import java.util.*;
import java.util.Map.*;
import java.util.stream.*;
import com.ibm.icu.number.*;
import com.ibm.icu.util.*;
public class IcuSpellout {
public static void main(String... args) {
Map<String, TreeSet<ULocale>> numbers = new TreeMap<>();
for(ULocale l : ULocale.getAvailableLocales()) {
String string = NumberFormatter.withLocale(l).format(1234567).toString();
numbers.computeIfAbsent(string, k -> new TreeSet<>()).add(l);
}
for(Entry<String, TreeSet<ULocale>> entry : numbers.entrySet()) {
System.out.println(entry.getKey() + " | " +
entry.getValue().stream().map(ULocale::toString).collect(Collectors.joining(", ")));
}
}
} |
I am not sure if I understand how the spec defines decimal formats in the static context. Is it currently allowed for an implementation to provide default formats (other than the unnamed one) that have not been specified by the user? For example, would it currently be legal for a processor to return a result for In XQFO 4.0, 4.7.1 Defining a decimal format says:
In XQuery 4.0, statically known decimal formats are defined as follows:
5.10 Decimal Format Declaration says:
|
* fn:format-number: Specifying decimal format. #340 * Minor revision
I’m closing this issue, as the PR was accepted, and the last question has been answered in today’s meeting (https://qt4cg.org/meeting/minutes/2024/03-05.html):
|
It would be nice if the decimal format for
fn:format-number
could also be supplied via an additional argument. The current syntax is:The syntax could be enhanced as follows:
If both
decimal-format-name
andformat
are supplied, an error should be raised.Edit 2023-05-02, adopted from a comment further below:
Next, language-specific default settings would be sensible. The existing syntax could be used:
As known from the other functions for formatting numbers and dates, it could be up to the implementation to decide which languages are supported. The defaults could be overwritten by custom decimal-format declarations in the prolog to ensure that a setting is applied, even if an implementation does not support it.
The text was updated successfully, but these errors were encountered: