Ejemplo n.º 1
0
        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() );
        }
Ejemplo n.º 2
0
		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);
		}
Ejemplo n.º 3
0
        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();
        }
Ejemplo n.º 4
0
 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;
             }
         }
     }
 }
Ejemplo n.º 5
0
Archivo: mn2db.cs Proyecto: olea/LuCAS
        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;
        }
Ejemplo n.º 6
0
		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>");
		}
Ejemplo n.º 7
0
        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();
        }
        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();
        }
Ejemplo n.º 9
0
		/// <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(); 
		}
Ejemplo n.º 10
0
        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();
        }
Ejemplo n.º 11
0
		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
			);
		}
Ejemplo n.º 12
0
        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) { }
            }
        }
Ejemplo n.º 13
0
        /* 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) { }
            }
        }
Ejemplo n.º 14
0
 /// <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);
 }
Ejemplo n.º 15
0
        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;
        }
Ejemplo n.º 16
0
 static void Main(string[] args)
 {
     XPathDocument myXPathDoc = new XPathDocument("..\\..\\..\\..\\SchoolJournal\\SchoolJournal\\Displaying\\entry.xml");
     XslTransform myXslTrans = new XslTransform();
     myXslTrans.Load("..\\..\\..\\..\\SchoolJournal\\SchoolJournal\\Displaying\\style1.xsl");
     XmlTextWriter myWriter = new XmlTextWriter("..\\..\\result.html", null);
     myXslTrans.Transform(myXPathDoc, null, myWriter);
 }
Ejemplo n.º 17
0
		public Toc2Html ()
		{
			transform = new XslTransform ();
			var assembly = Assembly.GetCallingAssembly ();
			var stream = assembly.GetManifestResourceStream ("toc-html.xsl");
			XmlReader xml_reader = new XmlTextReader (stream);
			transform.Load (xml_reader, null, null);
		}
Ejemplo n.º 18
0
        public XSLTRulesFileDriver(string xmlFileURI, XslTransform xslt)
            : base(xmlFileURI)
        {
            if (xslt == null)
                throw new BRERuleFatalException("Null is not a valid XslTransform");

            this.xslt = xslt;
        }
Ejemplo n.º 19
0
    	internal XmlOutput(XslTransform transform, XsltArgumentList xsltArgs, 
						   XPathNavigator navigator, XmlResolver resolverForXmlTransformed,
						   XmlReader[] readersToClose) {
			_transform = transform;
			_xsltArgs = xsltArgs;
			_navigator = navigator;
			_resolverForXmlTransformed = resolverForXmlTransformed;
			_readersToClose = readersToClose;
		}
Ejemplo n.º 20
0
 public string generateHtml(string xmlpath)
 {
     string xslpath = ranker.lib.libConfig.GetConfigPath() +  Path.DirectorySeparatorChar + "result.xsl";
     XslTransform xslt = new XslTransform();
     xslt.Load(xslpath);
     string htmlpath =  ranker.lib.libConfig.GetConfigPath() + Path.DirectorySeparatorChar +"temp.html";
     xslt.Transform(xmlpath,htmlpath );
     return htmlpath;
 }
Ejemplo n.º 21
0
        public string MakeBegripTxt(XElement begripDoc)
        {
            XslTransform tr = new XslTransform();
            tr.Load(Path.Combine(NSBundle.MainBundle.ResourcePath,"Xml2iPhone.xslt"));

            var txt = new StringWriter();
            tr.Transform(begripDoc.CreateNavigator(), null, txt);

            return txt.ToString();
        }
Ejemplo n.º 22
0
		public void Translate( string destinationFile )
		{
			XslTransform transform = new XslTransform();
			transform.Load( new XmlTextReader( Assembly.GetExecutingAssembly().GetManifestResourceStream( "NDoc.UsersGuideStager.xslt.htmlcontents.xslt" ) ), null, null );

			XmlDocument doc = new XmlDocument();
			doc.Load( TransformHtmlToXml() );

			transform.Transform( doc, null, File.CreateText( destinationFile ), null );
		}
Ejemplo n.º 23
0
        internal static void Main()
        {
            /* this is deprecated, but only for homework purposes */
            XslTransform sheetTransrormer = new XslTransform();
            sheetTransrormer.Load("../../../styleXSLT.xslt");
            sheetTransrormer.Transform("../../../catalogue.xml", "../../transformedCatalogue.html");
            Console.WriteLine("Result is in folder solution.");

            /*I leave on you to find difference with last task...*/
        }
Ejemplo n.º 24
0
        static void Main(string[] args)
        {

            XPathDocument xPathDoc = new XPathDocument("../../../Tasks1-Task6AndTask8/catalogue.xml");
            XslTransform xslTransformer = new XslTransform();
            xslTransformer.Load("../../Catalogue.xslt");

            XmlTextWriter writer = new XmlTextWriter("../../catalogue.html", Encoding.UTF8);
            xslTransformer.Transform(xPathDoc, null, writer);
        }
Ejemplo n.º 25
0
        public static string TransformFromMemory(XmlDocument xml, string xstlModel)
        {
            XslTransform xslt = new XslTransform();
            xslt.Load(xstlModel);

            StringWriter sr = new StringWriter();

            xslt.Transform(xml, null, sr);
            return sr.ToString();
        }
Ejemplo n.º 26
0
 public static string TransformXMLStream(string xmlStream,string xslPath)
 {
     XmlDocument xmlDoc = new XmlDocument();
       XslTransform xslDoc = new XslTransform();
       xmlDoc.LoadXml(xmlStream);
       xslDoc.Load(xslPath);
       StringWriter sw = new StringWriter();
       xslDoc.Transform(xmlDoc,null,sw);
       return sw.GetStringBuilder().ToString();
 }
Ejemplo n.º 27
0
        public static void Main(string [] rgstrArgs)
        {
            XmlDocument xml = new XmlDocument ();
            xml.Load (rgstrArgs [0]);

            XslTransform xsl = new XslTransform ();
            xsl.Load (rgstrArgs [1]);

            xsl.Transform (xml, null, Console.Out);
        }
Ejemplo n.º 28
0
    static public string Transform (string xmldata, string xsluri)
    {
        // FIXME: PONER TRY/CATCH PARA EVITAR MOSTRAR EXPLOSIONES DEL TRANSFORM
        //
        // CARGA LA HOJA DE ESTILOS
        System.Xml.Xsl.XslTransform xslt = new System.Xml.Xsl.XslTransform ();
        try
        {
            xslt.Load (System.AppDomain.CurrentDomain.BaseDirectory + "/Public/xml/" + xsluri);
        }
        catch (System.IO.FileNotFoundException)
        {
            System.Console.WriteLine ("No se ha encontrado el fichero {0}", xsluri);
            return "Template no encontrado";
        }

        // LEER ENTRADA
        System.Xml.XmlReader xrd;
        try
        {
            xrd = new XmlTextReader (new System.IO.StringReader (xmldata));
        }
        catch (System.ArgumentNullException)
        {
            return "[Contenido vacio (1)]";
        }

        // EJECUTAMOS Y PASAMOS A STRING
        XPathDocument xpd;
        try
        {
            xpd = new XPathDocument (xrd);
        }
        catch (System.Xml.XmlException ex)
        {
            return "[xml fuente incorrecto, error: " + ex.Message + "]";
        }
        XmlResolver xrs = new XmlSecureResolver (new XmlUrlResolver (), new PermissionSet (PermissionState.Unrestricted));
        XmlReader xr = xslt.Transform (xpd, null, xrs);
        xrd.Close ();

        // Output results to string
        XmlDocument xd = new XmlDocument ();
        xd.Load (xr);
        System.IO.StringWriter sw = new System.IO.StringWriter ();
        try
        {
            xd.Save (sw);
        }
        catch (System.InvalidOperationException ex)
        {
            return "[resultado incorrecto: "+ ex.Message +"]";
        }
        return sw.ToString ();
    }
Ejemplo n.º 29
0
        public static string Transform(string model, string xstlModel)
        {
            XslTransform xslt = new XslTransform();
            xslt.Load(xstlModel);
            XPathDocument xpathdocument = new XPathDocument(model);

            StringWriter sr = new StringWriter();

            xslt.Transform(xpathdocument, null, sr);
            return sr.ToString();
        }
Ejemplo n.º 30
0
		// It is indicated by ThreadManager.StartDebug().
		internal void Run ()
		{
			custom_cache = new Hashtable ();
			transform = (XslTransform) Activator.CreateInstance (typeof (XslTransform), BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.CreateInstance, null, new object [] {injector}, CultureInfo.CurrentCulture);
			debugger.LoadStylesheet (transform);
			output = new XmlNodeWriter (false);
			debugger.Transform (transform, output);

			if (Completed != null)
				Completed (this, new XsltCompleteEventArgs ());
		}