Browse Source

2003-08-19 Ben Maurer <[email protected]>

	* Compiler.cs, XslOutput.cs, XslStylesheet.cs,
	XslTransformProcessor.cs: move output logic from XslStylesheet to
	Compiler.
	* XslVariable.cs: sync to API changes
	* ManagedXslTransform.cs: sync to API changes

svn path=/trunk/mcs/; revision=17404
Ben Maurer 22 years ago
parent
commit
d633cbcbc5

+ 4 - 0
mcs/class/System.XML/Mono.Xml.Xsl.Operations/ChangeLog

@@ -1,3 +1,7 @@
+2003-08-19 Ben Maurer  <[email protected]>
+
+	* XslVariable.cs: sync to API changes.
+
 2003-08-18 Ben Maurer  <[email protected]>
 
 	* *.cs: Support for xsl:output. (Oleg)

+ 1 - 1
mcs/class/System.XML/Mono.Xml.Xsl.Operations/XslVariable.cs

@@ -47,7 +47,7 @@ namespace Mono.Xml.Xsl.Operations {
 			} else if (content != null) {
 				XmlNodeWriter w = new XmlNodeWriter ();
 				//TODO: which outputter should be used here?
-				Outputter outputter = new XmlOutputter(w, p.CompiledStyle.Style.Outputs);
+				Outputter outputter = new XmlOutputter(w, p.Outputs);
 				p.PushOutput (outputter);
 				content.Evaluate (p);
 				p.PopOutput ();

+ 6 - 0
mcs/class/System.XML/Mono.Xml.Xsl/ChangeLog

@@ -1,3 +1,9 @@
+2003-08-19 Ben Maurer  <[email protected]>
+
+	* Compiler.cs, XslOutput.cs, XslStylesheet.cs,
+	XslTransformProcessor.cs: move output logic from XslStylesheet to
+	Compiler.
+
 2003-08-18 Ben Maurer  <[email protected]>
 
 	* XslOutput.cs: add support for encoding.

+ 20 - 2
mcs/class/System.XML/Mono.Xml.Xsl/Compiler.cs

@@ -32,8 +32,9 @@ namespace Mono.Xml.Xsl {
 		ExpressionStore exprStore;
 		XmlNamespaceManager nsMgr;
 		ArrayList keys;
+		Hashtable outputs;
 		
-		public CompiledStylesheet (XslStylesheet style, Hashtable globalVariables, Hashtable attrSets, ExpressionStore exprStore, XmlNamespaceManager nsMgr, ArrayList keys)
+		public CompiledStylesheet (XslStylesheet style, Hashtable globalVariables, Hashtable attrSets, ExpressionStore exprStore, XmlNamespaceManager nsMgr, ArrayList keys, Hashtable outputs)
 		{
 			this.style = style;
 			this.globalVariables = globalVariables;
@@ -41,12 +42,14 @@ namespace Mono.Xml.Xsl {
 			this.exprStore = exprStore;
 			this.nsMgr = nsMgr;
 			this.keys = keys;
+			this.outputs = outputs;
 		}
 		public Hashtable Variables {get{return globalVariables;}}
 		public XslStylesheet Style { get { return style; }}
 		public ExpressionStore ExpressionStore {get{return exprStore;}}
 		public XmlNamespaceManager NamespaceManager {get{return nsMgr;}}
 		public ArrayList Keys {get { return keys;}}
+		public Hashtable Outputs { get { return outputs; }}
 		
 		public XslGeneralVariable ResolveVariable (QName name)
 		{
@@ -77,6 +80,7 @@ namespace Mono.Xml.Xsl {
 		XmlResolver res;
 		
 		XslStylesheet rootStyle;
+		Hashtable outputs = new Hashtable ();
 				
 		public CompiledStylesheet Compile (XPathNavigator nav, XmlResolver res, Evidence evidence)
 		{
@@ -86,6 +90,8 @@ namespace Mono.Xml.Xsl {
 
 			if (!nav.MoveToFirstChild ()) throw new Exception ("WTF?");
 				
+			outputs [""] = new XslOutput ("");
+				
 			while (nav.NodeType != XPathNodeType.Element) nav.MoveToNext();
 			
 			PushInputDocument (nav);
@@ -98,7 +104,7 @@ namespace Mono.Xml.Xsl {
 			}
 			this.rootStyle = new XslStylesheet (this);
 			
-			return new CompiledStylesheet (rootStyle, globalVariables, attrSets, exprStore, nsMgr, keys);
+			return new CompiledStylesheet (rootStyle, globalVariables, attrSets, exprStore, nsMgr, keys, outputs);
 		}
 		
 #region Input
@@ -371,6 +377,18 @@ namespace Mono.Xml.Xsl {
 			keys.Add (key);
 		}
 #endregion
+		
+		public void CompileOutput ()
+		{
+			XPathNavigator n = Input;
+			string uri = n.GetAttribute ("href", "");
+			XslOutput output = outputs [uri] as XslOutput;
+			if (output == null) {
+				output = new XslOutput (uri);
+				outputs.Add (uri, output);
+			}
+			output.Fill (n);
+		}
 	}
 	
 	public class VariableScope {

+ 3 - 2
mcs/class/System.XML/Mono.Xml.Xsl/XslOutput.cs

@@ -28,14 +28,15 @@ namespace Mono.Xml.Xsl
 		XML,
 		HTML,
 		Text,
-		Custom
+		Custom,
+		Unknown
 	}
 	
 	public class XslOutput	// also usable for xsl:result-document
 	{
 		string uri;
 		QName customMethod;
-		OutputMethod method = OutputMethod.XML; 
+		OutputMethod method = OutputMethod.Unknown; 
 		string version;
 		Encoding encoding = System.Text.Encoding.UTF8;
 		bool omitXmlDeclaration;

+ 1 - 13
mcs/class/System.XML/Mono.Xml.Xsl/XslStylesheet.cs

@@ -43,8 +43,6 @@ namespace Mono.Xml.Xsl {
 		// [QName]=>XmlSpace
 		Hashtable parameters = new Hashtable ();
 		
-		// [string href]=>XslOutput
-		Hashtable outputs = new Hashtable ();
 		MSXslScriptManager msScripts = new MSXslScriptManager ();
 		XslTemplateTable templates;
 
@@ -89,10 +87,6 @@ namespace Mono.Xml.Xsl {
 			get { return parameters; }
 		}
 
-		public Hashtable Outputs {
-			get { return outputs; }
-		}
-
 		public MSXslScriptManager ScriptManager{
 			get { return msScripts; }
 		}
@@ -177,13 +171,7 @@ namespace Mono.Xml.Xsl {
 					break;
 					
 				case "output":
-					string uri = n.GetAttribute ("href", "");
-					XslOutput output = outputs [uri] as XslOutput;
-					if (output == null) {
-						output = new XslOutput (uri);
-						outputs.Add (uri, output);
-					}
-					output.Fill (n);
+					c.CompileOutput ();
 					break;
 					
 				case "template":

+ 2 - 0
mcs/class/System.XML/Mono.Xml.Xsl/XslTransformProcessor.cs

@@ -81,6 +81,8 @@ namespace Mono.Xml.Xsl {
 		{
 			return (Outputter)this.outputStack.Pop ();
 		}
+		
+		public Hashtable Outputs { get { return compiledStyle.Outputs; }}
 		#endregion
 		
 		#region Templates -- Apply/Call

+ 4 - 0
mcs/class/System.XML/System.Xml.Xsl/ChangeLog

@@ -1,3 +1,7 @@
+2003-08-19 Ben Maurer  <[email protected]>
+
+	* ManagedXslTransform.cs: sync to API changes.
+
 2003-08-18 Ben Maurer  <[email protected]>
 
 	* ManagedXslTransform.cs, XslTransformImpl.cs: Add support for

+ 4 - 10
mcs/class/System.XML/System.Xml.Xsl/ManagedXslTransform.cs

@@ -28,7 +28,7 @@ namespace System.Xml.Xsl {
 
 		public override void Transform (XPathNavigator input, XsltArgumentList args, XmlWriter output, XmlResolver resolver)
 		{
-			Outputter outputter = new XmlOutputter(output, s.Style.Outputs);
+			Outputter outputter = new XmlOutputter(output, s.Outputs);
 			bool wroteStartDocument = false;
 			if (output.WriteState == WriteState.Start) {
 				outputter.WriteStartDocument ();
@@ -40,15 +40,9 @@ namespace System.Xml.Xsl {
 		}
 
 		public override void Transform (XPathNavigator input, XsltArgumentList args, TextWriter output, XmlResolver resolver) {
-			XslOutput xslOutput = (XslOutput)s.Style.Outputs[String.Empty];
-			if (xslOutput == null) {
-				//No xsl:output - subject to output method autodetection, XML for a while
-				XmlWriter w = new XmlTextWriter(output);
-				Transform(input, args, w, resolver);
-				w.Close ();
-				return;
-			}				
+			XslOutput xslOutput = (XslOutput)s.Outputs[String.Empty];
 			switch (xslOutput.Method) {
+				case OutputMethod.Unknown: // TODO: handle xml vs html
 				case OutputMethod.XML:
 					XmlWriter w = new XmlTextWriter(output);
 					Transform(input, args, w, resolver);
@@ -66,7 +60,7 @@ namespace System.Xml.Xsl {
 		
 		public override void Transform (XPathNavigator input, XsltArgumentList args, Stream output, XmlResolver resolver)
 		{
-			XslOutput xslOutput = (XslOutput)s.Style.Outputs[String.Empty];
+			XslOutput xslOutput = (XslOutput)s.Outputs[String.Empty];
 			if (xslOutput == null)
 				Transform (input, args, new StreamWriter (output), resolver);
 			else