本文整理汇总了C#中Saxon.Api.Processor类的典型用法代码示例。如果您正苦于以下问题:C# Processor类的具体用法?C# Processor怎么用?C# Processor使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Processor类属于Saxon.Api命名空间,在下文中一共展示了Processor类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Transform
public static void Transform(Uri StyleSheet, String Input,Encoding Encoding,out String Output)
{
Processor processor = new Processor();
XdmNode input = processor.NewDocumentBuilder().Build(new XmlTextReader(new StringReader(Input)));
processor.SetProperty("http://saxon.sf.net/feature/preferJaxpParser", "true");
XsltCompiler compiler = processor.NewXsltCompiler();
XsltExecutable executable = compiler.Compile(StyleSheet);
XsltTransformer transformer = executable.Load();
transformer.InitialContextNode = input;
Serializer serializer = new Serializer();
MemoryStream stream = new MemoryStream();
System.IO.StreamWriter writer = new StreamWriter(stream);
serializer.SetOutputWriter(writer);
transformer.Run(serializer);
Output = Encoding.GetString(stream.ToArray());
writer.Close();
stream.Close();
}
示例2: Xsl2Processor
public Xsl2Processor()
{
// Create a Processor instance.
_processor = new Processor();
_compiler = _processor.NewXsltCompiler();
}
示例3: XQueryCompiler
// internal constructor: the public interface is a factory method
// on the Processor object
internal XQueryCompiler(Processor processor)
{
this.processor = processor;
this.config = processor.config;
this.env = config.newStaticQueryContext();
env.setModuleURIResolver(new DotNetStandardModuleURIResolver(processor.XmlResolver));
}
示例4: XsltCompiler
// internal constructor: the public interface is a factory method
// on the Processor object
internal XsltCompiler(Processor processor)
{
this.processor = processor;
this.config = processor.config;
this.factory = new TransformerFactoryImpl(config);
this.info = new JCompilerInfo();
info.setURIResolver(config.getURIResolver());
info.setErrorListener(config.getErrorListener());
}
示例5: ImportSchematron
public static string ImportSchematron(string baseDir, string schemaPath, string xsltPath)
{
// Builds a new XSLT file from a schematron file.
// This only needs to be done when the schematron file changes.
var sxnProc = new Processor();
var outPath = xsltPath;
var baseXsltPath = Path.Combine(baseDir, @"Content\Saxon\");
var schConverter = new string[]
{
baseXsltPath + "iso_dsdl_include.xsl",
baseXsltPath + "iso_abstract_expand.xsl",
baseXsltPath + "iso_svrl_for_xslt2.xsl"
};
var schemaUri = new Uri(schemaPath);
var xslComp = sxnProc.NewXsltCompiler();
//////transform-1/////
var xslUri = new Uri(schConverter[0]);
var xslExec = xslComp.Compile(xslUri);
var xslTrans = xslExec.Load();
var domOut1 = new DomDestination(new XmlDocument());
using(var fs = File.Open(schemaPath, FileMode.Open, FileAccess.Read))
{
xslTrans.SetInputStream(fs, schemaUri); // set baseUri
xslTrans.Run(domOut1);
}
//////transform-2/////
xslUri = new Uri(schConverter[1]);
xslExec = xslComp.Compile(xslUri);
xslTrans = xslExec.Load();
var domOut2 = new DomDestination(new XmlDocument());
var docBuilder = sxnProc.NewDocumentBuilder();
docBuilder.BaseUri = schemaUri;
var inputDoc2 = docBuilder.Wrap(domOut1.XmlDocument);
xslTrans.InitialContextNode = inputDoc2;
xslTrans.Run(domOut2);
//////transform-3/////
xslUri = new Uri(schConverter[2]);
xslExec = xslComp.Compile(xslUri);
xslTrans = xslExec.Load();
var inputDoc3 = docBuilder.Wrap(domOut2.XmlDocument);
xslTrans.InitialContextNode = inputDoc3;
var serializer = new Serializer();
using (TextWriter tw = new StreamWriter(outPath, false))
{
serializer.SetOutputWriter(tw);
serializer.SetOutputProperty(Serializer.INDENT, "no");
xslTrans.Run(serializer);
}
return outPath;
}
示例6: Main
static void Main(string[] args)
{
String s1 = @"<xsl:stylesheet version='2.0' xmlns:xsl='http://www.w3.org/1999/XSL/Transform'><xsl:output method='xml' indent='yes'/><xsl:template match='/'>";
String s2 = "This is running an XSLT engine by <xsl:value-of select=\"system-property('xsl:vendor')\" /> <a href=\"{system-property('xsl:vendor-url')}\"><xsl:value-of select=\"system-property('xsl:vendor-url')\" /></a> implementing XSLT v<xsl:value-of select=\"system-property('xsl:version')\" /> ";
String s3 = @"\n<xsl:apply-templates/></xsl:template><xsl:template match='@*|node()'> ";
String s4 = @"<xsl:copy><xsl:apply-templates select='@*|node()'/></xsl:copy></xsl:template></xsl:stylesheet>";
String str = s1 + s2 + s3 + s4;
//Run Saxon
//new SaxonTransform().doTransform(args, "Transform");
//Run Saxon s9 api
// Create a Processor instance.
Processor processor = new Processor();
// Load the source document.
XdmNode input = processor.NewDocumentBuilder().Build(XmlReader.Create(new StringReader(str)));
XsltCompiler compiler = processor.NewXsltCompiler();
//although it is not required in this example, we need to set otherwise exception will be thrown
compiler.BaseUri = new Uri("http://dummyurl.com");
// Create a transformer for the stylesheet.
XsltTransformer transformer = compiler.Compile(XmlReader.Create(new StringReader(str))).Load();
// BaseOutputUri is only necessary for xsl:result-document.
//transformer.BaseOutputUri = new Uri("http://dummyurl.com");
// Set the root node of the source document to be the initial context node.
transformer.InitialContextNode = input;
transformer.SetParameter(new QName("", "", "maxmin"), new XdmAtomicValue("parm1"));
transformer.SetParameter(new QName("", "", "pricestock"), new XdmAtomicValue("parm2"));
// Create a serializer.
Serializer serializer = new Serializer();
// Set the root node of the source document to be the initial context node
//transformer.InitialTemplate = new QName("","","go");
serializer.SetOutputWriter(Console.Out);
serializer.SetOutputProperty(Serializer.INDENT, "yes");
// serializer.SetOutputFile(Server.MapPath("test.html")); //for file
// Transform the source XML to System.out.
transformer.Run(serializer);
//Call the SaxonMediator
SaxonMediator mediator = new SaxonMediator();
//mediator.Transform(null, Template template, Package package)
//wait for user to exit
Console.ReadLine();
}
示例7: Process
private static XmlDocument Process (XmlReader funcSeq, XmlReader extTransform, Uri baseUri) {
Processor processor = new Processor();
XdmNode input = processor.NewDocumentBuilder().Build(funcSeq);
XsltCompiler compiler = processor.NewXsltCompiler();
compiler.BaseUri = baseUri;
XsltTransformer transformer = compiler.Compile(extTransform).Load();
transformer.InitialContextNode = input;
DomDestination result = new DomDestination();
transformer.Run(result);
return result.XmlDocument;
}
示例8: getLinkedDocument
private XdmNode getLinkedDocument(XdmNode element, Processor processor, bool validate)
{
String href = element.GetAttributeValue(xlinkHref);
DocumentBuilder builder = processor.NewDocumentBuilder();
Uri target = new Uri(element.BaseUri, href);
builder.IsLineNumbering = true;
if (validate) {
builder.SchemaValidationMode = SchemaValidationMode.Strict;
}
return builder.Build(target);
}
示例9: SaxonDotNetTransform
public SaxonDotNetTransform(string sTransformName, string sTargetLanguageCode)
: base(sTargetLanguageCode)
{
// Create a Processor instance.
m_processor = new Processor();
m_compiler = m_processor.NewXsltCompiler();
// Load transform from file
var uri = new Uri(sTransformName);
var errorList = new List<StaticError>();
m_compiler.ErrorList = errorList;
var t = m_compiler.Compile(uri);
m_transformer = t.Load();
}
示例10: Init
private void Init (HttpContext context) {
AppSettings baseXslt = new AppSettings();
String xsltUri = context.Server.MapPath(baseXslt.GetSetting("baseTemplate"));
Uri xUri = new Uri(xsltUri);
this._Resolver = new XmlUrlResolver();
this._Resolver.Credentials = CredentialCache.DefaultCredentials;
this._TemplateStream = (Stream)this._Resolver.GetEntity(xUri, null, typeof(Stream));
this._Processor = new Processor();
this._Compiler = _Processor.NewXsltCompiler();
this._Compiler.BaseUri = xUri;
this._Template = this._Compiler.Compile(_TemplateStream);
this._IS_INITIALIZED = true;
}
示例11: ProcessRequest
public void ProcessRequest(HttpContext context) {
_requestMethod = context.Request.HttpMethod;
_writer = context.Response.Output;
_context = context;
_processor = (Processor)context.Application["processor"];
_compiler = (XsltCompiler)context.Application["compiler"];
_serializer = (Serializer)context.Application["serializer"];
_resolver = (XmlUrlResolver)context.Application["resolver"];
_globalXsltParams = (Hashtable)context.Application["globalXsltParams"];
_sessionXsltParams = (Hashtable)context.Application["sessionXsltParams"];
_requestXsltParams = (Hashtable)context.Application["requestXsltParams"];
Hashtable xsltParams = new Hashtable();
foreach (DictionaryEntry param in _globalXsltParams) {
xsltParams[param.Key] = param.Value;
}
foreach (DictionaryEntry param in _sessionXsltParams) {
xsltParams[param.Key] = param.Value;
}
foreach (DictionaryEntry param in _requestXsltParams) {
xsltParams[param.Key] = param.Value;
}
_transformContext = new Context(context, _processor, _compiler, _serializer, _resolver, xsltParams);
switch (_requestMethod) {
case "GET": {
new Transform().Process(_transformContext);
break;
}
case "PUT": {
new Transform().Process(_transformContext);
break;
}
case "POST": {
new Transform().Process(_transformContext);
break;
}
case "DELETE": {
new Transform().Process(_transformContext);
break;
}
default: {
new Transform().Process(_transformContext);
break;
}
}
}
示例12: xml2HtmlTree
private string xml2HtmlTree()
{
XmlDocument xml = new XmlDocument();
xml.LoadXml(this.Xsd);
StreamReader xsl = new StreamReader(AppDomain.CurrentDomain.BaseDirectory + "/Areas/MSM/Resources/Stylesheets/xsd2htmlTree.xslt");
Processor processor = new Processor();
XdmNode input = processor.NewDocumentBuilder().Build(xml);
XsltTransformer transformer = processor.NewXsltCompiler().Compile(xsl).Load();
transformer.InitialContextNode = input;
StringWriter writer = new StringWriter();
Serializer serializer = new Serializer();
serializer.SetOutputWriter(writer);
transformer.Run(serializer);
return writer.ToString();
}
示例13: Main
static void Main(string[] args)
{
string infile = @"c:\daisybooks\verysimplebook\verysimplebook.xml";
string infile_dir = @"c:\daisybooks\verysimplebook\";
string xsltfile = @"c:\devel\amis\trunk\amis\bin\xslt\dtbook\dtbook2xhtml.xsl";
string outfile = @"c:\devel\amis\sandbox\dtbooktransformer_out.xml";
// Create a Processor instance.
Processor processor = new Processor();
// Load the source document
XdmNode input = processor.NewDocumentBuilder().Build(new Uri(infile));
// Create a transformer for the stylesheet.
XsltTransformer transformer =
processor.NewXsltCompiler().Compile(new Uri(xsltfile)).Load();
QName basedir = new QName("", "baseDir");
List<XdmAtomicValue> elementNames = new List<XdmAtomicValue>();
elementNames.Add(new XdmAtomicValue(infile_dir));
XdmValue basedir_value = new XdmValue(elementNames);
transformer.SetParameter(basedir, basedir_value);
// Set the user-written XmlResolver
UserXmlResolver runTimeResolver = new UserXmlResolver();
runTimeResolver.Message = "** Calling transformation-time XmlResolver: ";
transformer.InputXmlResolver = runTimeResolver;
// Set the root node of the source document to be the initial context node
transformer.InitialContextNode = input;
/*
* String outfile = "OutputFromXsltSimple2.xml";
Serializer serializer = new Serializer();
serializer.SetOutputStream(new FileStream(outfile, FileMode.Create, FileAccess.Write));
*/
// Create a serializer, with output to the standard output stream
Serializer serializer = new Serializer();
serializer.SetOutputWriter(Console.Out);
// Transform the source XML and serialize the result document
transformer.Run(serializer);
Console.ReadLine();
}
示例14: Main
static void Main(string[] args)
{
if ( args.Length < 2)
{
Console.Error.WriteLine("Syntax: demo <path-to-xml-file> <xpath-expression> [<num-iterations(default={0})>]", numIters);
return;
}
var file = args[0];
var xpath = args[1];
if ( args.Length > 2)
{
numIters = int.Parse(args[2]);
}
Console.WriteLine("Loading {0}", file);
var proc = new Processor();
var ms_xp = System.Xml.XPath.XPathExpression.Compile(xpath);
var xpc = proc.NewXPathCompiler();
var xpe = xpc.Compile(xpath);
var sel = xpe.Load();
var doc = XDocument.Load(file);
var ctx = proc.Wrap(doc);
sel.ContextItem = ctx;
var nt = new NameTable();
XmlDocument xd = new XmlDocument(nt);
xd.Load(file);
var ctxXmlDoc = proc.NewDocumentBuilder().Wrap(xd);
Console.WriteLine("Evaluating {0}", xpath);
Time(() => Saxon(sel), "XDoc (Saxon)");
Time(() => Native(ms_xp, doc), "XDoc (Native)");
sel.ContextItem = ctxXmlDoc;
Time(() => Saxon(sel), "XmlDoc (Saxon)");
Time(() => Native(ms_xp, xd), "XmlDoc (Native)");
}
示例15: RegisterExtensionFunctions
void RegisterExtensionFunctions(Processor processor, SaxonItemFactory itemFactory) {
IEnumerable<IEnumerable<Type>> builtInFunctions =
new IEnumerable<Type>[] {
new modules.exslt.common.Index(),
new modules.request.Index(),
new modules.response.Index(),
new modules.session.Index(),
new modules.util.Index(),
new modules.validation.Index(),
new modules.smtpclient.Index(),
new modules.expath.httpclient.Index(),
};
IEnumerable<IEnumerable<Type>> importedFunctions =
(from m in XPathModules.GetModuleAdaptersForProcessor(this.GetType())
let t = m.AdapterType
let isCollection = typeof(IEnumerable<Type>).IsAssignableFrom(t)
select (isCollection) ?
(IEnumerable<Type>)Activator.CreateInstance(t)
: new Type[] { t });
Type itemFactoryType = itemFactory.GetType();
foreach (var types in Enumerable.Concat(builtInFunctions, importedFunctions)) {
var functions =
from t in types
let ctor = t.GetConstructors().First()
let param = ctor.GetParameters()
let args = param.Select(p => p.ParameterType.IsAssignableFrom(itemFactoryType) ? (object)itemFactory : null).ToArray()
select (ExtensionFunctionDefinition)ctor.Invoke(args);
if (functions.Select(f => f.FunctionName.Uri).Distinct().Count() > 1)
throw new InvalidOperationException("Functions in module must belog to the same namespace.");
foreach (var fn in functions)
processor.RegisterExtensionFunction(fn);
}
}