Little experience used by Transform.

zhaozj2021-02-16  40

Little experience used by Transform. XSLT file:

If there is

...

It will become the result of the first part of the first part:

GHJ1976@9cbs.netDearbook Cash on delivery Order ... /> > .....

.....

but:

If there is no

... < Results after analysis:

ghj1976@9cbs.netDearbook cash on delivery order ... ....

This is not: .

The code called at this time is:

Private void button2_click (object sender, system.eventargs e) {string savefile = @ "c: /1.htm"; string xmlfile = @ "e: /myworks/test/trans/testwin/order.xml"; string xslfile = @ "E: /myworks/test/trans/testwin/order.xslt"; if (file.exists (savefile)) {file.delete (savefile);} filestream fs = new filestream (Savefile, FileMode.create); XmLDocument xmlDoc = new XmlDocument (); xmlDoc.Load (XmlFile); XPathNavigator nav = xmlDoc.DocumentElement.CreateNavigator (); XslTransform xmlXsl = new XslTransform (); xmlXsl.Load (XslFile); xmlXsl.Transform (nav, null, fs, NULL); XMLXSL = NULL; NAV = null; xmldoc = null; fs.close (); fs = null;} Later, according to Googidea's views, the code is changed to:

Private void button1_click (object sender, system.eventargs e) {string savefile = @ "c: /1.htm"; string xmlfile = @ "e: /myworks/test/trans/testwin/order.xml"; string xslfile = @ "E: /myworks/test/trans/testwin/order.xslt"; if (file.exists (savefile)) {file.delete (Savefile);} filestream fs = new filestream (savefile, filemode.create);

XmlTextWriter Writer = New XmlTextWriter (fs, system.text.encoding.default); Writer.Formatting = formatting.indented;

XmlDocument xmlDoc = new XmlDocument (); xmlDoc.Load (XmlFile); XPathNavigator nav = xmlDoc.DocumentElement.CreateNavigator (); XslTransform xmlXsl = new XslTransform (); xmlXsl.Load (XslFile); xmlXsl.Transform (nav, null, writer , NULL); XMLXSL = NULL; NAV = NULL; XMLDOC = NULL; fs.close (); fs = null;}

There is no such problem.

Similarly, the thoughts are provided, and then the above the two code is returned correctly. Reason: Old brother, if you specify XSL: Output = HTML, just how you write it? XML Version = "1.0" encoding = "utf-8"?>. In fact, why you can find this in the Help of Output: The default for the method attribute is Chosen As Follows. If any of the following conditions are True, The Default Output Method IS "HTML":

The root node of the result tree has an element child. The expanded-name of the first element child of the root node (that is, the document element) of the result tree has local part "html" (in any combination of uppercase and lowercase) and a null namespace URI. Any text nodes preceding the first element child of the root node of the result tree contain only white space characters. Otherwise, the default output method is "xml". Zee provided.

Specific discussion process

http://blog.joycode.com/ghj/posts/4080.aspx

转载请注明原文地址:https://www.9cbs.com/read-28357.html

New Post(0)