.net 带有自定义结果文档处理程序的Saxon序列化程序选项
嗨,我实现了一个自定义的结果文档处理程序来解析相关的URI并跟踪编写的文件.net 带有自定义结果文档处理程序的Saxon序列化程序选项,.net,xslt,saxon,.net,Xslt,Saxon,嗨,我实现了一个自定义的结果文档处理程序来解析相关的URI并跟踪编写的文件 private class ResultDocumentHandler : IResultDocumentHandler { private List<string> writtenFiles = new List<string>(); public List<string> WrittenFiles => this.writtenFiles; pub
private class ResultDocumentHandler : IResultDocumentHandler
{
private List<string> writtenFiles = new List<string>();
public List<string> WrittenFiles => this.writtenFiles;
public XmlDestination HandleResultDocument(string href, Uri baseUri)
{
if (href.Contains("%"))
href = Uri.UnescapeDataString(href);
try
{
Uri hrefUri = new Uri(href, true);
if (hrefUri.IsAbsoluteUri)
{
Directory.CreateDirectory(Path.GetDirectoryName(hrefUri.LocalPath));
Serializer serializer = new Serializer();
serializer.SetOutputFile(hrefUri.LocalPath);
writtenFiles.Add(hrefUri.LocalPath);
return serializer;
}
}
catch
{
// ignore
}
try
{
Uri absoluteUri = new Uri(baseUri, href, true);
Directory.CreateDirectory(Path.GetDirectoryName(absoluteUri.LocalPath));
Serializer serializer = new Serializer();
serializer.SetOutputFile(absoluteUri.LocalPath);
writtenFiles.Add(absoluteUri.LocalPath);
return serializer;
}
catch
{
// ignore
}
return new NullDestination();
}
}
私有类ResultDocumentHandler:IResultDocumentHandler
{
私有列表writenfiles=新列表();
public List writenfiles=>this.writenfiles;
公共XmlDestination HandlerResultDocument(字符串href,Uri baseUri)
{
如果(href.Contains(“%”)
href=Uri.UnescapeDataString(href);
尝试
{
Uri hrefUri=新Uri(href,true);
如果(hrefUri.ISABOURI)
{
CreateDirectory(Path.GetDirectoryName(hrefUri.LocalPath));
Serializer Serializer=新的序列化程序();
serializer.SetOutputFile(hrefUri.LocalPath);
writenfiles.Add(hrefUri.LocalPath);
返回序列化程序;
}
}
抓住
{
//忽略
}
尝试
{
Uri absoluteUri=新Uri(baseUri,href,true);
CreateDirectory(Path.GetDirectoryName(absoluteUri.LocalPath));
Serializer Serializer=新的序列化程序();
serializer.SetOutputFile(绝对URI.LocalPath);
writenfiles.Add(绝对URI.LocalPath);
返回序列化程序;
}
抓住
{
//忽略
}
返回新的NullDestination();
}
}
到目前为止还不错。但是当我创建一个新的序列化程序时,它不会使用xsl文件中给出的选项。例如,我使用了:
<xsl:result-document href="{$resultDoc}" method="html" omit-xml-declaration="yes" indent="no">
这些选项现在被忽略,因为我没有为序列化程序设置它们。但是如何在结果文档处理程序中访问它们?我想我可以使用Saxon.Api.XsltTransformer.GetOutputProperties()
访问xsl:output
的选项,但我需要特定xsl:result文档的选项
有什么方法可以做到这一点吗?我认为没有任何简单的方法可以做到这一点。我已将此记录在
您可以做的是忽略Saxon.Api包中的ResultDocumentHandler机制,并下拉到Java定义的OutputURIResolver。您可以编写一个实现OutputURIResolver接口并返回StreamResult的C#类,并在支持XsltTransformer的控制器接口上进行设置。这很麻烦,因为您必须将saxon9 DLL和一些IKVM DLL添加到您的项目中,这样您就可以针对IKVM提供的底层Java API的C#转换进行编程。我想这就是为什么我们添加了ResultDocumentHandler接口,但是我们没有仔细考虑用例。谢谢Michael。也许我以后再试试你的建议。很高兴知道,这一点现在已得到跟踪,并将在将来得到修复。我很期待。