本文整理汇总了C#中System.Xml.Xsl.XslTransform类的典型用法代码示例。如果您正苦于以下问题:C# XslTransform类的具体用法?C# XslTransform怎么用?C# XslTransform使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
XslTransform类属于System.Xml.Xsl命名空间,在下文中一共展示了XslTransform类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: MatchRoot
public void MatchRoot()
{
XmlDocument xsltDoc = new XmlDocument();
xsltDoc.LoadXml( @"
<xsl:stylesheet version='1.0'
xmlns:xsl='http://www.w3.org/1999/XSL/Transform'>
<xsl:output method='xml' omit-xml-declaration='no' encoding='UTF-8'/>
<xsl:template match='/'><root>Matched</root></xsl:template>
</xsl:stylesheet>
" );
XslTransform xslt = new XslTransform();
xslt.Load( xsltDoc );
StringBuilder builder = new StringBuilder();
XmlWriter writer = new XmlTextWriter( new StringWriter( builder ) );
CollectionOfSimple c = new CollectionOfSimple( true );
ObjectXPathContext context = new ObjectXPathContext();
context.DetectLoops = true;
XPathNavigator nav = context.CreateNavigator( c );
xslt.Transform( nav, null, writer, null );
writer.Close();
Assert.AreEqual( "<root>Matched</root>", builder.ToString() );
}
示例2: InvalidStylesheet
public void InvalidStylesheet ()
{
XmlDocument doc = new XmlDocument ();
doc.LoadXml ("<xsl:element xmlns:xsl='http://www.w3.org/1999/XSL/Transform' />");
XslTransform t = new XslTransform ();
t.Load (doc);
}
示例3: BindAuto
private void BindAuto(Rubric rub)
{
Result.ResultList ress =
new Rubrics(Globals.CurrentIdentity).GetResults(rub.ID, GetCurrentSub());
if (ress.Count == 0) {
divAuto.InnerHtml = "<i>There are no results for this evaluation item</i>";
return;
}
AutoResult res = ress[0] as AutoResult;
MemoryStream xmlstr = new MemoryStream(Encoding.ASCII.GetBytes(res.XmlResult));
XslTransform xslt = new XslTransform();
XPathDocument xpathdoc = new XPathDocument(xmlstr);
XPathNavigator nav = xpathdoc.CreateNavigator();
XPathDocument xsldoc = new XPathDocument(
Path.Combine(Globals.WWWDirectory, "Xml/reshtml.xslt"));
StringBuilder strb = new StringBuilder();
xslt.Load(xsldoc, null, null);
xslt.Transform(xpathdoc, null, new XmlTextWriter(new StringWriter(strb)) , (XmlResolver)null);
divAuto.InnerHtml = strb.ToString();
}
示例4: Main
static void Main(string[] args)
{
XslTransform xslt = new XslTransform();
xslt.Load(@"..\Transforms\PAWSSKHtmlMapper.xsl");
string[] astrFiles;
astrFiles = Directory.GetFiles(".", "*.xml");
if (astrFiles.Length > 0)
{
foreach (string strFile in astrFiles)
{
try
{
string strDestFile = Path.Combine(@"..\HTMs",
Path.GetFileNameWithoutExtension(strFile));
strDestFile += ".htm";
Console.WriteLine("Making {0} from {1}", strDestFile, strFile);
xslt.Transform(strFile, strDestFile);
}
catch (Exception exc)
{
Console.WriteLine("Error: " + exc);
return;
}
}
}
}
示例5: TransformDirectory
public static bool TransformDirectory(string source)
{
string stylesheet = "mn2db.xsl";
string destination = "docbook" + Path.DirectorySeparatorChar;
// create destination directory if needed
string destdir = Directory.GetCurrentDirectory() + Path.DirectorySeparatorChar + destination;
try {
if(!Directory.Exists(destdir)) {
Directory.CreateDirectory(destdir);
}
// transform the documents in the directory
string[] filelist = Directory.GetFiles(source,"*.xml");
XslTransform transform = new XslTransform();
transform.Load(stylesheet);
foreach(string sourcefile in filelist) {
string destfile = destdir + Path.GetFileName(sourcefile);
Console.WriteLine("Transforming {0}",sourcefile);
transform.Transform(sourcefile, destfile);
}
} catch(Exception e) {
throw new Mn2DbTransformException(e.ToString());
}
return true;
}
示例6: TransformingTest
public void TransformingTest()
{
XslTransform tx = new XslTransform();
tx.Load(new XmlTextReader(
Globals.GetResource(this.GetType().Namespace + ".test.xsl")));
XmlReader xtr = new XmlTransformingReader(
new XmlTextReader(
Globals.GetResource(this.GetType().Namespace + ".input.xml")),
tx);
//That's it, now let's dump out XmlTransformingReader to see what it returns
StringWriter sw = new StringWriter();
XmlTextWriter w = new XmlTextWriter(sw);
w.Formatting = Formatting.Indented;
w.WriteNode(xtr, false);
xtr.Close();
w.Close();
Assert.AreEqual(sw.ToString(), @"<parts>
<item SKU=""1001"" name=""Lawnmower"" price=""299.99"" />
<item SKU=""1001"" name=""Electric drill"" price=""99.99"" />
<item SKU=""1001"" name=""Hairdrier"" price=""39.99"" />
</parts>");
}
示例7: Transform
public static string Transform(string xml,string xslFile)
{
XslTransform transform = new XslTransform();
XsltArgumentList args = new XsltArgumentList();
//define the xslt rendering file
//get the iterators for the root and context item
XPathDocument xmlDoc = new XPathDocument(new StringReader(xml));
XPathNavigator iter = xmlDoc.CreateNavigator();
//define and add the xslt extension classes
//Sitecore.Xml.Xsl.XslHelper sc = new Sitecore.Xml.Xsl.XslHelper();
XsltHelper xslt = new XsltHelper();
args.AddExtensionObject("http://www.rlmcore.vn/helper", xslt);
//add parameters
args.AddParam("item", "", iter);
args.AddParam("currentitem", "", iter.Select("."));
//define the stream which will contain the result of xslt transformation
//StringBuilder sb = new StringBuilder();
//TextWriter stream = new FileStream(new MemoryStream(Encoding.ASCII.GetBytes(sb.ToString())));
System.IO.StringWriter stream = new System.IO.StringWriter();
//load xslt rendering to XslTransform class
transform.Load(xslFile);
//perform a transformation with the rendering
transform.Transform(iter, args, stream);
return stream.ToString();
}
示例8: GetDataSummary
protected virtual string GetDataSummary(Stream xsltStream)
{
DataSet data = this.GetDataSet;
if (xsltStream == null || data == null)
return null;
Stream dsStream = new MemoryStream();
data.WriteXml(dsStream);
TextWriter tw = new StringWriter();
try
{
XslTransform xsl = new XslTransform();
XmlDocument XSLTDoc = new XmlDocument();
XSLTDoc.Load(xsltStream);
XmlDocument dataDoc = new XmlDocument();
dataDoc.LoadXml(data.GetXml());
XPathNavigator stylesheet = XSLTDoc.CreateNavigator();
xsl.Load(stylesheet, null, null);
XPathNavigator dataNav = dataDoc.CreateNavigator();
xsl.Transform(dataNav, null, tw, null);
}
catch (Exception ex)
{
return null;
}
return tw.ToString();
}
示例9: GetStatesXMLString
/// <summary>
/// This function retuns list of states for a given country as XML Document in a string
/// and this value is used in client side java script to populate state combo box.
/// Functionality: Transform the CountriesAndStates xml string into another XML string having the single country
/// and states under that country.
/// </summary>
public string GetStatesXMLString(string countryName)
{
//Creates a XslTransform object and load the CountriesAndStates.xsl file
XslTransform transformToCountryNode = new XslTransform();
transformToCountryNode.Load(new XPathDocument(HttpContext.Current.Server.MapPath("~/xmlxsl/CountriesAndStates.xsl")).CreateNavigator(), new XmlUrlResolver());
//TransformToCountryNode.Load(new XPathDocument(HttpContext.Current.Server.MapPath("~/xmlxsl/CountriesAndStates.xsl")).CreateNavigator(), new XmlUrlResolver(), this.GetType().Assembly.Evidence);
//Creating the XSLT parameter country-name and setting the value
XsltArgumentList xslArgs = new XsltArgumentList();
xslArgs.AddParam("country-name", "", countryName);
// Memory stream to store the result of XSL transform
MemoryStream countryNodeMemoryStream = new MemoryStream();
XmlTextWriter countryNodeXmlTextWriter = new XmlTextWriter(countryNodeMemoryStream, Encoding.UTF8);
countryNodeXmlTextWriter.WriteProcessingInstruction("xml", "version='1.0' encoding='UTF-8'");
//transforming the current XML string to get the state XML string
transformToCountryNode.Transform(xPathDoc, xslArgs, countryNodeXmlTextWriter);
//TransformToCountryNode.Transform(XPathDoc, XslArgs, CountryNodeXmlTextWriter, null);
//reading the XML string using StreamReader and return the same
countryNodeXmlTextWriter.Flush();
countryNodeMemoryStream.Position = 0;
StreamReader countryNodeStreamReader = new StreamReader(countryNodeMemoryStream);
return countryNodeStreamReader.ReadToEnd();
}
示例10: ViewGui
public ViewGui()
{
Stetic.Gui.Build(this, typeof(Sofia.Views.WelcomeView.ViewGui));
//Ajout d'une page d'accueil avec un navigateur web
htmlControl = new MozillaControl();
this.Add(htmlControl);
htmlControl.Show();
string datadir = Directory.GetCurrentDirectory() + "/";
// build simple xml which XSLT will process into XHTML
string myxml = "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>" +
"<WelcomePage>" +
"<ResourcePath>" + datadir + "</ResourcePath>" +
BuildRecentFoldersXml() +
"</WelcomePage>";
XmlDocument inxml = new XmlDocument();
inxml.LoadXml(myxml);
XslTransform xslt = new XslTransform();
xslt.Load(datadir + "WelcomePage.xsl");
StringWriter fs = new StringWriter();
xslt.Transform(inxml, null, fs, null);
htmlControl.Html = fs.ToString();
}
示例11: Parse
public static void Parse(
XmlDocument xmlMetadata_in,
string xsltTemplateURL_in,
Hashtable xsltParameters_in,
StringWriter parsedOutput_in
) {
#region XsltArgumentList _xsltparameters = new XsltArgumentList().AddParam(...);
XsltArgumentList _xsltparameters = new XsltArgumentList();
IDictionaryEnumerator _denum = xsltParameters_in.GetEnumerator();
_denum.Reset();
while (_denum.MoveNext()) {
_xsltparameters.AddParam(
_denum.Key.ToString(),
"",
System.Web.HttpUtility.UrlEncode(
_denum.Value.ToString()
)
);
}
#endregion
XPathNavigator _xpathnav = xmlMetadata_in.CreateNavigator();
XslTransform _xslttransform = new XslTransform();
_xslttransform.Load(
xsltTemplateURL_in
);
_xslttransform.Transform(
_xpathnav,
_xsltparameters,
parsedOutput_in,
null
);
}
示例12: RunXslt
public void RunXslt(String xsltFile, String xmlDataFile, String outputXml)
{
XPathDocument input = new XPathDocument(xmlDataFile);
XslTransform myXslTrans = new XslTransform() ;
XmlTextWriter output = null;
try
{
myXslTrans.Load(xsltFile);
output = new XmlTextWriter(outputXml, null);
output.Formatting = Formatting.Indented;
myXslTrans.Transform(input, null, output);
}
catch (Exception e)
{
String msg = e.Message;
if (msg.IndexOf("InnerException") >0)
{
msg = e.InnerException.Message;
}
MessageBox.Show("Error: " + msg + "\n" + e.StackTrace, "Xslt Error File: " + xsltFile, MessageBoxButtons.OK, MessageBoxIcon.Error);
}
finally
{
try { output.Close(); }
catch (Exception) { }
}
}
示例13: RunXSLT
/* KCS: 2012/03/19 - Changed to be able to pass args to the template.
*
* xslt <xsltFile> <inputXml> <outputFile> <parm1Name> = <parm1Value> <parm2Name> = <parm2Value> .....
*/
public void RunXSLT(String xsltFile, String xmlDataFile, String outFile, XsltArgumentList xsltArgs )
{
XPathDocument input = new XPathDocument(xmlDataFile);
XslTransform myXslTrans = new XslTransform();
XmlTextWriter output = null;
try
{
myXslTrans.Load(xsltFile);
output = new XmlTextWriter(outFile, null);
output.Formatting = Formatting.Indented;
myXslTrans.Transform(input, xsltArgs, output);
}
catch (Exception e)
{
Console.WriteLine(e.StackTrace);
Console.WriteLine("Error: " + e.Message);
}
finally
{
try { output.Close(); }
catch (Exception) { }
}
}
示例14: XmlTransformingReader
/// <summary>
/// Creates XmlTransformingReader with given XmlReader, stylesheet URI,
/// XsltArgumentList and Xmlresolver.
/// </summary>
/// <param name="parentReader">Source XML as XmlReader</param>
/// <param name="transformSource">URI of the stylesheet to transform the source</param>
/// <param name="args">Arguments to the transformation</param>
/// <param name="resolver">XmlResolver to resolve URIs in document() function</param>
public XmlTransformingReader(XmlReader parentReader,
string transformSource, XsltArgumentList args, XmlResolver resolver)
{
XPathDocument doc = new XPathDocument(parentReader);
XslTransform xslt = new XslTransform();
xslt.Load(transformSource);
_outReader = xslt.Transform(doc, args, resolver);
}
示例15: Init
public new void Init(object objParam)
{
#pragma warning disable 0618
xsltSameInstance = new XslTransform();
#pragma warning restore 0618
_strPath = Path.Combine(@"TestFiles\", FilePathUtil.GetTestDataPath(), @"XsltApi\");
return;
}