【发布时间】:2013-10-03 19:06:32
【问题描述】:
我正在使用 Saxon-HE 的 .net 版本。
我编写了一些代码来设置 XSLT 转换,其中源 XSLT 是从外部传入的(而不是在运行时从文件中读取)。
这是我的代码的 sn-p:
Saxon.Api.Processor processor = new Saxon.Api.Processor();
// Feed the XSLT into Saxon
XmlDocument document = new XmlDocument();
document.LoadXml(xslt);
Saxon.Api.XdmNode input = processor.NewDocumentBuilder().Build(document);
Saxon.Api.XsltCompiler xsltCompiler = processor.NewXsltCompiler();
Saxon.Api.XsltExecutable xsltExecutable = xsltCompiler.Compile(input);
Saxon.Api.XsltTransformer xsltTransformer = xsltExecutable.Load();
// Create The stream that will contain the transformed XML.
MemoryStream transformedXmlStream = new MemoryStream();
xsltTransformer.InputXmlResolver = null;
// Input the XML into the transformer.
xsltTransformer.InitialContextNode = processor.NewDocumentBuilder().Build(inputXml);
// Set up the serializer that will output the result.
Saxon.Api.Serializer dataSerializer = processor.NewSerializer(transformedXmlStream);
// Run the transformation and get the output as a stream.
xsltTransformer.Run(dataSerializer);
到目前为止,这段代码运行良好!
但是,我遇到了新要求的问题。我被要求使用 document() 函数实现一些功能,这需要另一个具有自己 BaseURI 的 XML 文档。
这个其他文档将作为字符串或流直接馈送到程序中,就像 XSLT 和输入 XML 一样。问题是我很难弄清楚如何将文档提供给撒克逊人,document() 函数将引用该文档。
如何使用document() 函数在 Saxon XSLT 中读取 XML 流?
【问题讨论】: