2019 年 .NET Core 的 XSLT3 选项
XSLT3 Options for .NET Core in 2019
有人在 2019 年让 XSLT3 转换在 .NET Core 2.x+ 中工作吗?
似乎向 MS 请求 XSLT2/3 support hasn't moved forwards, and the Saxon people have other priorities, especially given the IKVM closedown。
进程内 XSLT 转换是否有其他替代方案?目前,我唯一的选择似乎是通过外部服务或一些不受欢迎的(对我们来说)COM 风格的方法来包装一些东西,这会涉及大量数据编组,从而损害性能。
不幸的是,IKVM 从未支持 .NET Core,因此无法使 Saxon 的 .NET 版本在该环境中工作。在 Saxonica 中,我们一直在探索支持 .NET 的替代途径,但我们还没有发现任何有希望的东西。 (有人喜欢为 .NET 实现 Kotlin 吗?)
我不知道使用 XMLPrime 或 Exselt 有什么可能,两者都以 .NET 为目标。
2021 年更新
Saxonica 现在在 .NET 5 上发布 SaxonCS,该产品是通过使用自定义转换器将 SaxonJ 的 Java 代码转换为 C# 源代码构建的。
有一种方法可以在 .NET Core 上使用 Saxon:通过 Transform.exe 运行 作为进程。
您可以使用类似这样的代码:
/// <summary>Transform XML inputFile using xsltFile and parameters. Save the result to the outputFile.</summary>
public void Transform(string inputFile, string outputFile, string xsltFile, NameValueCollection parameters)
{
//Search for the instalation path on the system
string path = GetInstalPath(@"Software\Saxonica\SaxonHE-N\Settings", "InstallPath");
string exePath = Path.Combine(path, "bin", "Transform.exe");
string parametersCmd = null;
//Set indicidual parameters
foreach (string parameter in parameters)
{
parametersCmd += String.Format("{0}={1} ", parameter, parameters[parameter]);
}
//set arguments for Transform.exe
string arguments = string.Format("-s:\"{1}\" -xsl:\"{0}\" -o:\"{3}\" {2}", xsltFile, inputFile, parametersCmd, outputFile);
//
ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.FileName = exePath;
startInfo.Arguments = arguments;
startInfo.RedirectStandardOutput = true;
startInfo.RedirectStandardError = true;
startInfo.UseShellExecute = false;
startInfo.CreateNoWindow = true;
int waitingTime = 5 * 60 * 1000; //5 minutes; time in milliseconds
Process processTemp = new Process();
processTemp.StartInfo = startInfo;
processTemp.EnableRaisingEvents = true;
try
{
processTemp.Start();
processTemp.WaitForExit(waitingTime);
}
catch (Exception e)
{
throw;
}
}
static string GetInstalPath(string comName, string key)
{
RegistryKey comKey = Registry.CurrentUser.OpenSubKey(comName);
if (comKey == null)
return null;
string clsid = (string)comKey.GetValue(key);
return clsid;
}
SaxonCS EE 已发布并可与 .NET 5 和 .NET 6 (RC/preview) 一起使用,并且这种方式允许将 XSLT 3、XPath 3.1 和 XQuery 3.1 与 .NET Core 一起使用。但是,它仅在商业许可下可用,但您可以使用试用许可对其进行测试,从 Saxonica 下载的网址为 https://www.saxonica.com/download/dotnet.xml, also on NuGet as https://www.nuget.org/packages/SaxonCS/。
有人在 2019 年让 XSLT3 转换在 .NET Core 2.x+ 中工作吗?
似乎向 MS 请求 XSLT2/3 support hasn't moved forwards, and the Saxon people have other priorities, especially given the IKVM closedown。
进程内 XSLT 转换是否有其他替代方案?目前,我唯一的选择似乎是通过外部服务或一些不受欢迎的(对我们来说)COM 风格的方法来包装一些东西,这会涉及大量数据编组,从而损害性能。
不幸的是,IKVM 从未支持 .NET Core,因此无法使 Saxon 的 .NET 版本在该环境中工作。在 Saxonica 中,我们一直在探索支持 .NET 的替代途径,但我们还没有发现任何有希望的东西。 (有人喜欢为 .NET 实现 Kotlin 吗?)
我不知道使用 XMLPrime 或 Exselt 有什么可能,两者都以 .NET 为目标。
2021 年更新
Saxonica 现在在 .NET 5 上发布 SaxonCS,该产品是通过使用自定义转换器将 SaxonJ 的 Java 代码转换为 C# 源代码构建的。
有一种方法可以在 .NET Core 上使用 Saxon:通过 Transform.exe 运行 作为进程。
您可以使用类似这样的代码:
/// <summary>Transform XML inputFile using xsltFile and parameters. Save the result to the outputFile.</summary>
public void Transform(string inputFile, string outputFile, string xsltFile, NameValueCollection parameters)
{
//Search for the instalation path on the system
string path = GetInstalPath(@"Software\Saxonica\SaxonHE-N\Settings", "InstallPath");
string exePath = Path.Combine(path, "bin", "Transform.exe");
string parametersCmd = null;
//Set indicidual parameters
foreach (string parameter in parameters)
{
parametersCmd += String.Format("{0}={1} ", parameter, parameters[parameter]);
}
//set arguments for Transform.exe
string arguments = string.Format("-s:\"{1}\" -xsl:\"{0}\" -o:\"{3}\" {2}", xsltFile, inputFile, parametersCmd, outputFile);
//
ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.FileName = exePath;
startInfo.Arguments = arguments;
startInfo.RedirectStandardOutput = true;
startInfo.RedirectStandardError = true;
startInfo.UseShellExecute = false;
startInfo.CreateNoWindow = true;
int waitingTime = 5 * 60 * 1000; //5 minutes; time in milliseconds
Process processTemp = new Process();
processTemp.StartInfo = startInfo;
processTemp.EnableRaisingEvents = true;
try
{
processTemp.Start();
processTemp.WaitForExit(waitingTime);
}
catch (Exception e)
{
throw;
}
}
static string GetInstalPath(string comName, string key)
{
RegistryKey comKey = Registry.CurrentUser.OpenSubKey(comName);
if (comKey == null)
return null;
string clsid = (string)comKey.GetValue(key);
return clsid;
}
SaxonCS EE 已发布并可与 .NET 5 和 .NET 6 (RC/preview) 一起使用,并且这种方式允许将 XSLT 3、XPath 3.1 和 XQuery 3.1 与 .NET Core 一起使用。但是,它仅在商业许可下可用,但您可以使用试用许可对其进行测试,从 Saxonica 下载的网址为 https://www.saxonica.com/download/dotnet.xml, also on NuGet as https://www.nuget.org/packages/SaxonCS/。