本文整理汇总了C#中System.Xml.Xsl.XsltArgumentList类的典型用法代码示例。如果您正苦于以下问题:C# XsltArgumentList类的具体用法?C# XsltArgumentList怎么用?C# XsltArgumentList使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
XsltArgumentList类属于System.Xml.Xsl命名空间,在下文中一共展示了XsltArgumentList类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CopyAdditionalParams
public static void CopyAdditionalParams(Dictionary<string, string> additionalParams, XsltArgumentList arguments)
{
foreach (KeyValuePair<string, string> pair in additionalParams)
{
arguments.AddParam(pair.Key, "", pair.Value);
}
}
示例2: XTransformToWriter
public static void XTransformToWriter(this Linq.XElement xmlDoc, TextWriter writer,
Linq.XElement xmlXslt = null, // Action<XslCompiledTransform> onXsltLoad = null,
object xsltExtension = null,
string urn = "urn:request-info")
{
XslCompiledTransform trans = new XslCompiledTransform();
//if (onXsltLoad != null)
// onXsltLoad(trans);
//else
trans.Load(xmlXslt.CreateReader());
if (xsltExtension != null)
{
XsltArgumentList xslArg = new XsltArgumentList();
xslArg.AddExtensionObject(urn, xsltExtension);
// XTransformTo(trans, xmlDoc.CreateReader(), xslArg, writer);
// var results = writer;
XmlReader input = xmlDoc.CreateReader();
XmlWriterSettings outputSettings = trans.OutputSettings;
using (XmlWriter writerXml = XmlWriter.Create(writer, outputSettings))
{
trans.Transform(input, arguments: xslArg, results: writerXml,
documentResolver: XmlNullResolver.Singleton); // XsltConfigSection.CreateDefaultResolver());
writerXml.Close();
}
}
else
{
// trans.Transform(xmlDoc.CreateNavigator() as IXPathNavigable, arguments: null, results: writer);
XTransformTo(trans, xmlDoc.CreateReader(), null, writer);
}
}
示例3: RenderRelatedNews
private void RenderRelatedNews()
{
if (Request.QueryString[ConstantsManager.NewsGUID] == null)
return;
//int _newsID = 0; Int32.TryParse(Request.QueryString[ConstantsManager.NewsID], out _newsID);
//if (_newsID == 0)
// return;
string guid = Request.QueryString[ConstantsManager.NewsGUID].ToString();
NewsItem _news = NewsItemManager.GetByGUID(guid);
if (null == _news)
return;
XmlDocument xDoc = NewsItemManager.GetNewsByKeywordAsXML(_news.Keywords, _news.ID);
if (null == xDoc)
return;
XslTemplate xslTemplate = XslTemplateManager.GetByID(XSLID);
if (null == xslTemplate)
return;
XsltArgumentList arguments = new XsltArgumentList();
arguments.AddExtensionObject("obj:CategoryViewer", this);
_news.Keywords = "";
_news.ViewCount++;
NewsItemManager.Update(_news);
string _html = UtilitiesManager.TransformXMLWithXSLText(xDoc.OuterXml, xslTemplate.Details, arguments);
dvData.InnerHtml = _html;
}
示例4: LoadMenuItem
void LoadMenuItem()
{
int menuID = 0;
int.TryParse(Request.QueryString[CMSConfig.QueryString.MenuID], out menuID);
if (base.XSLTemplateID > 0 && menuID > 0)
{
string xslPath = CMSWebHelper.GetXSLTemplateFilePath(base.XSLTemplateID);
xslPath = XSLTemplateManager.GetXSLTemplatePath(xslPath, base.XSLTemplateID);
XsltArgumentList arguments = new XsltArgumentList();
arguments.AddExtensionObject("CMS:UserControl", this);
Menu menu = new Menu();
xmlMenu.DocumentContent = MenuManager.GetMenuItemTemplateXml(menuID, CMSContext.LanguageID, out menu);
xmlMenu.TransformSource = xslPath;
xmlMenu.TransformArgumentList = arguments;
xmlMenu.DataBind();
bool SetPageTitle = false;
bool.TryParse(this.Attributes["SetPageTitle"], out SetPageTitle);
if (SetPageTitle && menu != null)
{
this.Page.Title = menu.Name;
}
}
}
示例5: TransformHtml
public static void TransformHtml(XmlSerializer serializer, object report, Type reportType, string outputFilePath, GeneratorConfiguration generatorConfiguration, string xsltFile)
{
var xmlOutputWriter = new StringWriter();
serializer.Serialize(xmlOutputWriter, report);
XslCompiledTransform xslt = new XslCompiledTransform();
var xsltSettings = new XsltSettings(true, false);
XmlResolver resourceResolver;
var reportName = reportType.Name.Replace("Generator", "");
using (var xsltReader = GetTemplateReader(reportType, reportName, xsltFile))
{
resourceResolver = new XmlResourceResolver();
xslt.Load(xsltReader, xsltSettings, resourceResolver);
}
var xmlOutputReader = new XmlTextReader(new StringReader(xmlOutputWriter.ToString()));
XsltArgumentList argumentList = new XsltArgumentList();
argumentList.AddParam("feature-language", "", generatorConfiguration.FeatureLanguage.Name);
argumentList.AddParam("tool-language", "", generatorConfiguration.ToolLanguage.Name);
using (var xmlTextWriter = new XmlTextWriter(outputFilePath, Encoding.UTF8))
{
xslt.Transform(xmlOutputReader, argumentList, xmlTextWriter, resourceResolver);
}
}
示例6: Init
public new void Init(object objParam)
{
// Get parameter info
_strPath = Path.Combine(@"TestFiles\", FilePathUtil.GetTestDataPath(), @"XsltApi\");
xsltArg1 = new XsltArgumentList();
MyObject obj1 = new MyObject(1, _output);
MyObject obj2 = new MyObject(2, _output);
MyObject obj3 = new MyObject(3, _output);
MyObject obj4 = new MyObject(4, _output);
MyObject obj5 = new MyObject(5, _output);
xsltArg1.AddExtensionObject("urn:my-obj1", obj1);
xsltArg1.AddExtensionObject("urn:my-obj2", obj2);
xsltArg1.AddExtensionObject("urn:my-obj3", obj3);
xsltArg1.AddExtensionObject("urn:my-obj4", obj4);
xsltArg1.AddExtensionObject("urn:my-obj5", obj5);
xsltArg1.AddParam("myArg1", szEmpty, "Test1");
xsltArg1.AddParam("myArg2", szEmpty, "Test2");
xsltArg1.AddParam("myArg3", szEmpty, "Test3");
xsltArg1.AddParam("myArg4", szEmpty, "Test4");
xsltArg1.AddParam("myArg5", szEmpty, "Test5");
return;
}
示例7: Transform
public void Transform()
{
var xsltTemplateReader = new XmlTextReader(_xsltPath);
var emptyDocumentReader = XmlReader.Create(new System.IO.StringReader("<empty />"));
var settings = new XmlWriterSettings();
//settings.ConformanceLevel = ConformanceLevel.Fragment;
settings.Indent = true;
using (var outputWriter = XmlWriter.Create(_outputPath, settings))
{
var xsltSettings = new XsltSettings();
XsltArgumentList argumentList = new XsltArgumentList();
var extensions = new XsltExtensionMethods(_settings);
argumentList.AddExtensionObject("http://core.com/config", extensions);
argumentList.AddExtensionObject("http://paralect.com/config", extensions);
var transformer = new XslCompiledTransform(true);
transformer.Load(xsltTemplateReader, xsltSettings, null);
transformer.Transform(emptyDocumentReader,argumentList, outputWriter);
}
}
示例8: Register
/// <exclude />
public static void Register(XsltArgumentList argumentList)
{
foreach(string providerName in XslExtensionsProviderRegistry.XslExtensionsProviderNames)
{
List<Pair<string, object>> extensions;
try
{
extensions = XslExtensionsProviderPluginFacade.CreateExtensions(providerName);
}
catch(Exception ex)
{
string message = "Failed to get xsl extensions from provider '{0}'".FormatWith(providerName);
LoggingService.LogError("XslExtensionsManager", new InvalidOperationException(message, ex));
continue;
}
if(extensions != null)
{
foreach (Pair<string, object> pair in extensions)
{
argumentList.AddExtensionObject(pair.First, pair.Second);
}
}
}
}
示例9: Transform
public void Transform(string inputFilePath, string outputFilePath, KeyValueConfigurationCollection settings)
{
var xsltTemplateReader = new XmlTextReader(inputFilePath);
var emptyDocumentReader = XmlReader.Create(new System.IO.StringReader("<empty />"));
var writerSettings = new XmlWriterSettings();
//settings.ConformanceLevel = ConformanceLevel.Fragment;
writerSettings.Indent = true;
using (var outputWriter = XmlWriter.Create(outputFilePath, writerSettings))
{
var xsltSettings = new XsltSettings();
XsltArgumentList argumentList = new XsltArgumentList();
var extensions = new XsltExtensionMethods(settings);
argumentList.AddExtensionObject("http://core.com/config", extensions);
argumentList.AddExtensionObject("http://setty.net/config", extensions);
var transformer = new XslCompiledTransform(true);
transformer.Load(xsltTemplateReader, xsltSettings, null);
transformer.Transform(emptyDocumentReader, argumentList, outputWriter);
}
}
示例10: WriteProcessed
/// <summary>
/// Writes the results of XSLT transformation into the specified TextWriter.
/// </summary>
public static void WriteProcessed(string templateName, XsltArgumentList argumentList, XDocument data, TextWriter outStream)
{
using (XmlReader reader = data.CreateReader())
{
GetCompiledTransform(templateName).Transform(reader, argumentList, outStream);
}
}
示例11: Transform
/// <summary>
/// Performs a XSL Transformation
/// </summary>
/// <param name="styleSheet">Style Sheet path relative to Application Base directory</param>
/// <param name="xslArguments">XSL Arguments</param>
/// <param name="inputStream">Input Stream</param>
/// <param name="outputStream">Out put Stream as Ref (output Stream is initialized if it is null</param>
public void Transform(String styleSheet, Dictionary<String, String> xslArguments, Stream inputStream, ref Stream outputStream)
{
try
{
XsltSettings xsltSettings = new XsltSettings();
xsltSettings.EnableScript = true;
xsltSettings.EnableDocumentFunction = true;
XsltArgumentList xslArgumentList = new XsltArgumentList();
foreach (String key in xslArguments.Keys)
{
xslArgumentList.AddParam(key, "", xslArguments[key]);
}
XslCompiledTransform transformer = new XslCompiledTransform();
String stylesheetpath = AppDomain.CurrentDomain.BaseDirectory + styleSheet;
transformer.Load(stylesheetpath, xsltSettings, new XmlUrlResolver());
if (null == outputStream)
{
outputStream = new MemoryStream();
}
StreamWriter streamWriter = new StreamWriter(outputStream);
XmlReaderSettings xmlReaderSettings = new XmlReaderSettings();
xmlReaderSettings.DtdProcessing = DtdProcessing.Ignore;
XmlReader xmlReader = XmlReader.Create(inputStream, xmlReaderSettings);
XmlTextWriter writer = new XmlTextWriter(outputStream,System.Text.Encoding.UTF8);
writer.Formatting = Formatting.None;
transformer.Transform(xmlReader, xslArgumentList, writer);
}
catch (Exception exception)
{
throw exception;
}
}
示例12: WriteToStreamAsync
public override Task WriteToStreamAsync(Type type, object value, Stream writeStream, System.Net.Http.HttpContent content, System.Net.TransportContext transportContext)
{
var taskSource = new TaskCompletionSource<object>();
try
{
var xml = (XmlNode) value;
var documentElement = ((XmlDocument)value).DocumentElement;
if (documentElement != null && documentElement.LocalName == "RDF") {
((XmlDocument)xml).Save(writeStream);
}
else {
var parameters = new XsltArgumentList();
var transform = XsltRepository.Get("RdfToHtml.xslt");
transform.Transform(xml, parameters, writeStream);
}
taskSource.SetResult(null);
}
catch (Exception e)
{
taskSource.SetException(e);
}
return taskSource.Task;
}
示例13: CreateInstance
/// <summary>
/// Creates an instance of the given type from the specified Internet resource.
/// </summary>
/// <param name="htmlUrl">The requested URL, such as "http://Myserver/Mypath/Myfile.asp".</param>
/// <param name="xsltUrl">The URL that specifies the XSLT stylesheet to load.</param>
/// <param name="xsltArgs">An <see cref="XsltArgumentList"/> containing the namespace-qualified arguments used as input to the transform.</param>
/// <param name="type">The requested type.</param>
/// <param name="xmlPath">A file path where the temporary XML before transformation will be saved. Mostly used for debugging purposes.</param>
/// <returns>An newly created instance.</returns>
public object CreateInstance(string htmlUrl, string xsltUrl, XsltArgumentList xsltArgs, Type type,
string xmlPath)
{
StringWriter sw = new StringWriter();
XmlTextWriter writer = new XmlTextWriter(sw);
if (xsltUrl == null)
{
LoadHtmlAsXml(htmlUrl, writer);
}
else
{
if (xmlPath == null)
{
LoadHtmlAsXml(htmlUrl, xsltUrl, xsltArgs, writer);
}
else
{
LoadHtmlAsXml(htmlUrl, xsltUrl, xsltArgs, writer, xmlPath);
}
}
writer.Flush();
StringReader sr = new StringReader(sw.ToString());
XmlTextReader reader = new XmlTextReader(sr);
XmlSerializer serializer = new XmlSerializer(type);
object o;
try
{
o = serializer.Deserialize(reader);
}
catch (InvalidOperationException ex)
{
throw new Exception(ex + ", --- xml:" + sw);
}
return o;
}
示例14: Render
public void Render(object source, HtmlTextWriter htmlWriter, TemplateDefinition liveDefinition)
{
var resolver = new PathResolver(liveDefinition.Folder);
var hostPage = DNNContext.Current.Page;
var args = new XsltArgumentList();
args.AddExtensionObject("urn:ddrmenu", new XsltFunctions());
args.AddExtensionObject("urn:dnngarden", new XsltFunctions());
args.AddParam("ControlID", "", DNNContext.Current.HostControl.ClientID);
args.AddParam("Options", "", ConvertToJson(liveDefinition.ClientOptions));
args.AddParam("DNNPath", "", hostPage.ResolveUrl(resolver.Resolve("/", PathResolver.RelativeTo.Dnn)));
args.AddParam("ManifestPath", "", hostPage.ResolveUrl(resolver.Resolve("/", PathResolver.RelativeTo.Manifest)));
args.AddParam("PortalPath", "", hostPage.ResolveUrl(resolver.Resolve("/", PathResolver.RelativeTo.Portal)));
args.AddParam("SkinPath", "", hostPage.ResolveUrl(resolver.Resolve("/", PathResolver.RelativeTo.Skin)));
liveDefinition.TemplateArguments.ForEach(a => args.AddParam(a.Name, "", a.Value));
HttpContext.Current.Items["Resolver"] = resolver;
using (var xmlStream = new MemoryStream())
{
Utilities.SerialiserFor(source.GetType()).Serialize(xmlStream, source);
xmlStream.Seek(0, SeekOrigin.Begin);
xsl.Transform(XmlReader.Create(xmlStream), args, htmlWriter);
}
}
示例15: BuildNavigator
public void BuildNavigator(string modelFilePath)
{
XmlResolver resolver = new XmlUrlResolver();
resolver.Credentials = CredentialCache.DefaultCredentials;
XmlTextReader tr = new XmlTextReader(modelFilePath);
XslCompiledTransform transform = new XslCompiledTransform();
transform.Load(this.stylesheetFilesPath + Path.DirectorySeparatorChar + "ModelTree.xsl",null,resolver);
XmlTextWriter tw = new XmlTextWriter(this.htmlFilesPath + Path.DirectorySeparatorChar + "ModelTree.htm", Encoding.UTF8);
XsltArgumentList al = new XsltArgumentList();
al.AddParam("modelBrowser","",this.localizer.GetValue("Globals","ModelBrowser"));
al.AddParam("glossary","",this.localizer.GetValue("Globals","Glossary"));
al.AddParam("stakeholders", "", this.localizer.GetValue("Globals", "Stakeholders"));
transform.Transform(tr,al,tw,null);
tw.Close();
tr.Close();
tr = new XmlTextReader(modelFilePath);
transform.Load(this.stylesheetFilesPath + Path.DirectorySeparatorChar + "HomePage.xsl",null,resolver);
tw = new XmlTextWriter(this.htmlFilesPath + Path.DirectorySeparatorChar + "main.htm",Encoding.UTF8);
al = new XsltArgumentList();
AssemblyName an = this.GetType().Assembly.GetName();
al.AddParam("version","",an.Version.ToString(3));
al.AddParam("model", "", this.localizer.GetValue("Globals", "Model"));
al.AddParam("author", "", this.localizer.GetValue("Globals", "Author"));
al.AddParam("company", "", this.localizer.GetValue("Globals", "Company"));
al.AddParam("creationDate", "", this.localizer.GetValue("Globals", "CreationDate"));
al.AddParam("exportPrintDate", "", this.localizer.GetValue("Globals", "ExportPrintDate"));
al.AddParam("now", "", Convert.ToString(DateTime.Now, DateTimeFormatInfo.InvariantInfo));
al.AddParam("release", "", this.localizer.GetValue("Globals", "Release"));
transform.Transform(tr,al,tw,null);
tw.Close();
tr.Close();
}