如何使用 Saxon HE 10.2 设置语言数据? [英] How to set language data with Saxon HE 10.2?

查看:51
本文介绍了如何使用 Saxon HE 10.2 设置语言数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用 Saxon HE 10.2 正确设置语言数据?我需要 XSLT 处理器输出当前日期,其中包含用德语写出的月份名称,例如 21.2020 年 10 月.不幸的是,处理器输出[语言:en]21.2020 年 10 月.Saxon PE 提供了开箱即用的所需输出.
这是我的 XSLT 代码:

How can I set language data correctly with Saxon HE 10.2? I need the XSLT Processor to output the current date with a month name written out in German, like 21. Oktober 2020. Unfortunately, the processor outputs [Language: en]21. October 2020. Saxon PE gives the desired output out of the box.
This is my XSLT code:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" version="3.0">
    <xsl:output method="text"/>
    <xsl:template match="/">
        <xsl:value-of select="format-dateTime(current-dateTime(), '[D]. [MNn] [Y]', 'de', (), ())"/>
    </xsl:template>
</xsl:stylesheet>

测试XML源代码文件是这样的:

The test XML source code file is like this:

<?xml version="1.0" encoding="UTF-8"?>
<root/>

在 Linux 中,我运行 java -cp $xsltProc $class -s:source.xml -xsl:stylesheet.xslt -o:result.
$xsltProc 是文件 saxon-he-10.2.jar 的路径.
$classnet.sf.saxon.Transform.
任何帮助将不胜感激.

In Linux, I run java -cp $xsltProc $class -s:source.xml -xsl:stylesheet.xslt -o:result.
$xsltProc is the path to the file saxon-he-10.2.jar.
$class is net.sf.saxon.Transform.
Any help would be greatly appreciated.

推荐答案

要开箱即用"支持德语日期格式,您需要 Saxon-PE 或更高版本.

To support German date formats "out of the box", you need Saxon-PE or higher.

请参阅 https://saxonica.com/documentation/index.html#!extensibility/config-extend/localizing/other-numberings

如果你想使用 Saxon-HE,你可以编译 net.sf.saxon.option.local.Numberer_de 类的开源代码,并在配置中注册:

If you want this with Saxon-HE, you can compile the open source code for class net.sf.saxon.option.local.Numberer_de and register it with the Configuration:

configuration.setLocalizerFactory(new LocalizerFactory() {
   public Numberer getNumberer(String language, String country) {
       if (lang.equals("de")) {
           return new Numberer_de();
       } else {
           ...
       }
   });

Numberer 代码位于 https://saxonica.plan.io/projects/saxon/repository/he/revisions/master/entry/latest10/hej/net/sf/saxon/option/local/Numberer_de.java

这篇关于如何使用 Saxon HE 10.2 设置语言数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆