2003-11-21 Atsushi Enomoto <ginga@kit.hi-ho.ne.jp>
authorAtsushi Eno <atsushieno@gmail.com>
Fri, 21 Nov 2003 19:21:24 +0000 (19:21 -0000)
committerAtsushi Eno <atsushieno@gmail.com>
Fri, 21 Nov 2003 19:21:24 +0000 (19:21 -0000)
* Compiler.cs : Modified decimal-format comparison code.
* Outputter.cs,
  TextOutputter.cs,
  GenericOutputter.cs : Added WriteState. Now WriteStartDocument() will
  be called only when required.
* HtmlEmitter.cs : Improved indentation stuff.
* XslDecimalFormat.cs : Added incomplete implementation of
  CheckSameAs() and FormatNumber().
* XslStylesheet.cs,
  XslTransformProcessor.cs : Changed XslStylesheet.StylesheetNamespaces
  from StringDictionary to ArrayList of QName (to keep order).

svn path=/trunk/mcs/; revision=20323

mcs/class/System.XML/Mono.Xml.Xsl/ChangeLog
mcs/class/System.XML/Mono.Xml.Xsl/Compiler.cs
mcs/class/System.XML/Mono.Xml.Xsl/GenericOutputter.cs
mcs/class/System.XML/Mono.Xml.Xsl/HtmlEmitter.cs
mcs/class/System.XML/Mono.Xml.Xsl/Outputter.cs
mcs/class/System.XML/Mono.Xml.Xsl/TextOutputter.cs
mcs/class/System.XML/Mono.Xml.Xsl/XslDecimalFormat.cs
mcs/class/System.XML/Mono.Xml.Xsl/XslStylesheet.cs
mcs/class/System.XML/Mono.Xml.Xsl/XslTransformProcessor.cs

index c147a10b1844acb1c47f682562f66258eff65822..a663cb07c478ab369061abd47831da7701a7a90e 100644 (file)
@@ -1,3 +1,17 @@
+2003-11-21 Atsushi Enomoto <ginga@kit.hi-ho.ne.jp>
+
+       * Compiler.cs : Modified decimal-format comparison code.
+       * Outputter.cs,
+         TextOutputter.cs,
+         GenericOutputter.cs : Added WriteState. Now WriteStartDocument() will
+         be called only when required. 
+       * HtmlEmitter.cs : Improved indentation stuff.
+       * XslDecimalFormat.cs : Added incomplete implementation of 
+         CheckSameAs() and FormatNumber().
+       * XslStylesheet.cs,
+         XslTransformProcessor.cs : Changed XslStylesheet.StylesheetNamespaces
+         from StringDictionary to ArrayList of QName (to keep order).
+
 2003-11-19 Atsushi Enomoto <ginga@kit.hi-ho.ne.jp>
 
        * XsltCompiledContext.cs : XsltGenerateId.Evaluate() should consider
index 392925daac18a2b9481ae7301fa3be5b6eb81bf5..eb4a7064d381a83c88cf739cb126b64f21caaa94 100644 (file)
@@ -404,11 +404,12 @@ namespace Mono.Xml.Xsl {
                public void CompileDecimalFormat ()
                {
                        QName nm = ParseQNameAttribute ("name");
+                       XslDecimalFormat df = new XslDecimalFormat (this);
                        
                        if (decimalFormats.Contains (nm))
-                               ((XslDecimalFormat)decimalFormats [nm]).CheckSameAs (this);
+                               ((XslDecimalFormat)decimalFormats [nm]).CheckSameAs (df);
                        else
-                               decimalFormats [nm] = new XslDecimalFormat (this);
+                               decimalFormats [nm] = df;
                }
 #endregion
 #region Static XSLT context
index 9b053f0ddf0cd49f802b6ed90cd10f784ddc988d..95ed20778c53deb511c5313c6a4f90eb80508b35 100644 (file)
@@ -70,13 +70,10 @@ namespace Mono.Xml.Xsl
                        switch (xslOutput.Method) {
                                
                                case OutputMethod.HTML:
-                                       Console.WriteLine ("WARNING: HTML output not fully supported, using XML output");
                                        _emitter = new HtmlEmitter (writer, xslOutput);
                                        break;
                                case OutputMethod.Unknown: //TODO: handle xml vs html
                                case OutputMethod.XML:
-                                       //TODO: XmlTextEmitter goes here
-                                       //_emitter = new XmlTextEmitter (writer);
                                        XmlTextWriter w = new XmlTextWriter (writer);
                                        if (xslOutput.Indent == "yes")
                                                w.Formatting = Formatting.Indented;
@@ -95,7 +92,10 @@ namespace Mono.Xml.Xsl
                /// when it's appropriate.
                /// </summary>
                private void CheckState ()
-               {               
+               {
+                       if (_state == WriteState.Start)
+                               WriteStartDocument ();
+
                        if (_state == WriteState.Element) {
                                //Push scope to allow to unwind namespaces scope back in WriteEndElement
                                //Subject to optimization - avoid redundant push/pop by moving 
@@ -142,6 +142,9 @@ namespace Mono.Xml.Xsl
                int _nsCount;
                public override void WriteStartElement (string prefix, string localName, string nsURI)
                {
+                       if (_state == WriteState.Start)
+                               WriteStartDocument ();
+
                        if (_state == WriteState.Prolog) {
                                //Seems to be the first element - take care of Doctype
                                if (_currentOutput.DoctypeSystem != null)
@@ -262,6 +265,8 @@ namespace Mono.Xml.Xsl
                public override bool CanProcessAttributes {
                        get { return canProcessAttributes; }
                }
+
+               public override WriteState WriteState { get { return _state; } }
                #endregion
        }
 }
index caa853c90abc81f71cab6e91ef508632f14ef2bb..90be15477b5b4abb16f9bf8103e631cb0cc7dbe4 100644 (file)
@@ -76,18 +76,52 @@ namespace Mono.Xml.Xsl
                        openElement = false;
                }
 
+               // FIXME: check all HTML elements' indentation.
                private void Indent (string elementName, bool alwaysOutputNewLine)
                {
                        if (!indent)
                                return;
                        switch (elementName.ToUpper ()) {
-                       case "FORM":
-                               return;
+                       case "ADDRESS":
+                       case "BDO":
+                       case "BLOCKQUOTE":
+                       case "BODY":
+                       case "BUTTON":
+                       case "CAPTION":
+                       case "CENTER":
+                       case "DD":
+                       case "DEL":
+                       case "DIR":
+                       case "DIV":
+                       case "DL":
+                       case "DT":
+                       case "FIELDSET":
+                       case "H1":
+                       case "H2":
+                       case "H3":
+                       case "H4":
+                       case "H5":
+                       case "H6":
+                       case "HEAD":
+                       case "HTML":
+                       case "IFRAME":
+                       case "INS":
+                       case "LI":
+                       case "MAP":
+                       case "MENU":
+                       case "NOFRAMES":
+                       case "NOSCRIPT":
+                       case "OBJECT":
+                       case "P":
+                       case "PRE":
+                       case "TD":
+                       case "TH":
+                               if (alwaysOutputNewLine || elementNameStack.Count > 0)
+                                       writer.Write ("\r\n");
+                               for (int i = 0; i < elementNameStack.Count; i++)
+                                               writer.Write ("  ");
+                               break;
                        }
-                       if (alwaysOutputNewLine || elementNameStack.Count > 0)
-                               writer.Write ("\r\n");
-                       for (int i = 0; i < elementNameStack.Count; i++)
-                                       writer.Write ("  ");
                }
 
                public override void WriteStartElement (string prefix, string localName, string nsURI)
index 3ce2d190451d9cbafb78eaff84fd35b8972a20a1..c558259161abf56308e9c9fa9e6b63eb329ebdc9 100644 (file)
@@ -8,6 +8,7 @@
 //
 
 using System;
+using System.Xml;
 
 namespace Mono.Xml.Xsl {
        /// <summary>
@@ -52,5 +53,7 @@ namespace Mono.Xml.Xsl {
                public virtual bool CanProcessAttributes {
                        get { return false; }
                }
+
+               public abstract WriteState WriteState { get; }
        }
 }
index e21db5c06e9d979f116e2b1dbddd3f603a21d869..d97d79c2f3be941cb88e475c646b91eb4728401f 100644 (file)
@@ -62,5 +62,7 @@ namespace Mono.Xml.Xsl {
                public override void Done () {
                        _writer.Flush ();
                }
+
+               public override WriteState WriteState { get { return WriteState.Start; } }
        }
 }
index 7f8186208faa2599fc7bfedc31817b2606b8d382..11f5dbc3896d0e17531a7bb2c7526a7cb2580fe3 100644 (file)
@@ -21,6 +21,10 @@ namespace Mono.Xml.Xsl {
                
                NumberFormatInfo info = new NumberFormatInfo ();
                char digit = '#', zeroDigit = '0', patternSeparator = ';';
+               XPathNavigator source;
+               string baseUri;
+               int lineNumber;
+               int linePosition;
 
                public static readonly XslDecimalFormat Default = new XslDecimalFormat ();
                
@@ -28,9 +32,17 @@ namespace Mono.Xml.Xsl {
                public XslDecimalFormat (Compiler c)
                {
                        XPathNavigator n = c.Input;
+
+                       IXmlLineInfo li = n as IXmlLineInfo;
+                       if (li != null) {
+                               lineNumber = li.LineNumber;
+                               linePosition = li.LinePosition;
+                       }
+                       baseUri = n.BaseURI;
+
                        if (n.MoveToFirstAttribute ()) {
                                do {
-                                       if (n.NamespaceURI != Compiler.XsltNamespace)
+                                       if (n.NamespaceURI != String.Empty)
                                                continue;
                                        
                                        switch (n.LocalName) {
@@ -58,10 +70,10 @@ namespace Mono.Xml.Xsl {
                                                case "per-mille":
                                                        info.PerMilleSymbol = n.Value;
                                                        break;
-                                               case "zero-digit":
+                                               case "digit":
                                                        digit = n.Value [0];
                                                        break;
-                                               case "digit":
+                                               case "zero-digit":
                                                        zeroDigit = n.Value [0];
                                                        break;
                                                case "pattern-separator":
@@ -74,17 +86,20 @@ namespace Mono.Xml.Xsl {
                                info.NegativeInfinitySymbol = info.NegativeSign + info.PositiveInfinitySymbol;
                        }
                }
-               
-               // check that the data in c is the same as this one, as we
-               // must do, per the spec.
-               public void CheckSameAs (Compiler c)
+
+               // TODO: complete comparison for XSLT spec. 12.3.
+               public void CheckSameAs (XslDecimalFormat other)
                {
-                       throw new NotImplementedException ();
+                       if (this.digit != other.digit ||
+                               this.patternSeparator != other.patternSeparator ||
+                               this.zeroDigit != other.zeroDigit)
+                               throw new XsltCompileException (null, other.baseUri, other.lineNumber, other.linePosition);
                }
                
+               // TODO: format pattern check.
                public string FormatNumber (double number, string pattern)
                {
-                       throw new NotImplementedException ();
+                       return number.ToString (pattern, info);
                }
        }
 }
\ No newline at end of file
index 77cf2c9122ec33773dde91f192f9f88e68b4a4bb..2fe6e546085eaeb798067499ddccb9e51b5b7fe9 100644 (file)
@@ -50,7 +50,7 @@ namespace Mono.Xml.Xsl {
                string version;
                XmlQualifiedName [] extensionElementPrefixes;
                XmlQualifiedName [] excludeResultPrefixes;
-               StringDictionary stylesheetNamespaces = new StringDictionary ();
+               ArrayList stylesheetNamespaces = new ArrayList ();
 
                // below are newly introduced in XSLT 2.0
                //  elements::
@@ -76,7 +76,7 @@ namespace Mono.Xml.Xsl {
                        get { return excludeResultPrefixes; }
                }
 
-               public StringDictionary StylesheetNamespaces {
+               public ArrayList StylesheetNamespaces {
                        get { return stylesheetNamespaces; }
                }
 
@@ -125,7 +125,7 @@ namespace Mono.Xml.Xsl {
                                        do {
                                                if (c.Input.Value == XsltNamespace)
                                                        continue;
-                                               this.stylesheetNamespaces.Add (c.Input.Name, c.Input.Value);
+                                               this.stylesheetNamespaces.Insert (0, new QName (c.Input.Name, c.Input.Value));
                                        } while (c.Input.MoveToNextNamespace (XPathNamespaceScope.Local));
                                        c.Input.MoveToParent ();
                                }
index 1eddf56b1343c54a6f57b32dc16de9d0f90abd4c..c086ff7c9f6a48e8b09ef245cd4bfc07092b2f06 100644 (file)
@@ -263,7 +263,8 @@ namespace Mono.Xml.Xsl {
                internal void TryStylesheetNamespaceOutput ()
                {
                        if (outputStylesheetXmlns) {
-                               foreach (string prefix in this.style.StylesheetNamespaces.Keys) {
+                               foreach (XmlQualifiedName qname in this.style.StylesheetNamespaces) {
+                                       string prefix = qname.Name;
                                        if (style.ExcludeResultPrefixes != null) {
                                                bool exclude = false;
                                                foreach (XmlQualifiedName exc in style.ExcludeResultPrefixes)
@@ -284,7 +285,7 @@ namespace Mono.Xml.Xsl {
                                                if (exclude)
                                                        continue;
                                        }
-                                       Out.WriteNamespaceDecl (prefix, this.style.StylesheetNamespaces [prefix]);
+                                       Out.WriteNamespaceDecl (prefix, qname.Namespace);
                                }
                                outputStylesheetXmlns = false;
                        }