2003-12-02 Atsushi Enomoto <ginga@kit.hi-ho.ne.jp>
authorAtsushi Eno <atsushieno@gmail.com>
Tue, 2 Dec 2003 05:14:43 +0000 (05:14 -0000)
committerAtsushi Eno <atsushieno@gmail.com>
Tue, 2 Dec 2003 05:14:43 +0000 (05:14 -0000)
* Compiler.cs : In FromListString(), it should use default ns,
  not unqualified one.
* GenericOutputter.cs : CheckState() - attribute's Prefix should take
  precedence.  Doctype should be written even if SYSTEM id is absent.
  Fixed possible multiple xmlns output.
* HtmlEmitter.cs :
  - Encoding output using META element.
  - Doctype name is fixed (html).
  - Double quotation on PUBLIC and SYSTEM missing.
  - Fixed incorrect tag name check for IMG.
  - '>' should not be escaped.
* XmlWriterEmitter.cs :
  Added newline before doctype.  In WriteComment(), "--" and tail
  '-' are not allowed (it escapes, while XmlWriter simply rejects).
* XslTransformProcessor.cs : cdata-section-elements should enclose
  direct child tests only.   Added PreserveWhitespace() (incomplete).
* XsltCompiledContext.cs : Implemented PreserveWhitespace() (incomplete).

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

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/XmlWriterEmitter.cs
mcs/class/System.XML/Mono.Xml.Xsl/XslTransformProcessor.cs
mcs/class/System.XML/Mono.Xml.Xsl/XsltCompiledContext.cs

index d88548543e91c7dacdd783bd1f0c13215a5e2815..a07c4292e58638958ecab01883a72109cc0a75e4 100644 (file)
@@ -1,3 +1,27 @@
+2003-12-02 Atsushi Enomoto <ginga@kit.hi-ho.ne.jp>
+
+       * Compiler.cs : In FromListString(), it should use default ns,
+         not unqualified one.
+       * GenericOutputter.cs : CheckState() - attribute's Prefix should take
+         precedence.  Doctype should be written even if SYSTEM id is absent.
+         Fixed possible multiple xmlns output.
+       * HtmlEmitter.cs :
+         - Encoding output using META element.
+         - Doctype name is fixed (html).
+         - Double quotation on PUBLIC and SYSTEM missing.
+         - Fixed incorrect tag name check for IMG.
+         - '>' should not be escaped.
+       * XmlWriterEmitter.cs :
+         Added newline before doctype.  In WriteComment(), "--" and tail
+         '-' are not allowed (it escapes, while XmlWriter simply rejects).
+       * XslTransformProcessor.cs : cdata-section-elements should enclose
+         direct child tests only.   Added PreserveWhitespace() (incomplete).
+       * XsltCompiledContext.cs : Implemented PreserveWhitespace() (incomplete).
+
+2003-11-28 Atsushi Enomoto <ginga@kit.hi-ho.ne.jp>
+
+       * IdPattern.cs : This should work against multiple ids.
+
 2003-11-27 Ben Maurer  <bmaurer@users.sourceforge.net>
 
        * Compiler.cs
index e9189365fb092d46a7dcdb665f1d7928bf1ee1ee..7fdf47b5c160a51aa71972c3a1a3ab0b9343c53f 100644 (file)
@@ -678,11 +678,9 @@ namespace Mono.Xml.Xsl {
        
        public class XslNameUtil
        {
-               static char [] wsChars = new char [] {' ', '\t', '\n', '\r'};
-
                public static QName [] FromListString (string names, XPathNavigator current)
                {
-                       string [] nameArray = names.Split (wsChars);
+                       string [] nameArray = names.Split (XmlChar.WhitespaceChars);
                        int idx = 0;
                        for (int i = 0; i < nameArray.Length; i++)
                                if (nameArray [i] != String.Empty)
@@ -693,12 +691,17 @@ namespace Mono.Xml.Xsl {
                        idx = 0;
                        for (int i = 0; i < nameArray.Length; i++)
                                if (nameArray [i] != String.Empty)
-                                       qnames [idx++] = FromString (nameArray [i], current);
+                                       qnames [idx++] = FromString (nameArray [i], current, true);
 
                        return qnames;
                }
 
                public static QName FromString (string name, XPathNavigator current)
+               {
+                       return FromString (name, current, false);
+               }
+
+               public static QName FromString (string name, XPathNavigator current, bool useDefaultXmlns)
                {
                        if (current.NodeType == XPathNodeType.Attribute)
                                (current = current.Clone ()).MoveToParent ();
@@ -707,8 +710,7 @@ namespace Mono.Xml.Xsl {
                        if (colon > 0)
                                return new QName (name.Substring (colon+ 1), current.GetNamespace (name.Substring (0, colon)));
                        else if (colon < 0)
-                               // Default namespace is not used for unprefixed names.
-                               return new QName (name, "");
+                               return new QName (name, useDefaultXmlns ? current.GetNamespace (String.Empty) : "");
                        else
                                throw new ArgumentException ("Invalid name: " + name);
                }
index 6cd08fe614232cab1d757cc857c8073c8c6c2a69..c171fab295ac25750a6acd5811bc6e9110087c86 100644 (file)
@@ -104,9 +104,9 @@ namespace Mono.Xml.Xsl
                                //Emit pending attributes
                                for (int i = 0; i < pendingAttributesPos; i++) {
                                        Attribute attr = pendingAttributes [i];
-                                       string prefix = _nsManager.LookupPrefix (attr.Namespace);
-                                       if (prefix == null)
-                                               prefix = attr.Prefix;
+                                       string prefix = attr.Prefix;
+                                       if (prefix == String.Empty)
+                                               prefix = _nsManager.LookupPrefix (attr.Namespace);
                                        _emitter.WriteAttributeString (prefix, attr.LocalName, attr.Namespace, attr.Value);
                                }
                                foreach (string prefix in _currentNsPrefixes) {
@@ -147,7 +147,8 @@ namespace Mono.Xml.Xsl
 
                        if (_state == WriteState.Prolog) {
                                //Seems to be the first element - take care of Doctype
-                               if (_currentOutput.DoctypeSystem != null)
+                               // Note that HTML does not require SYSTEM identifier.
+                               if (_currentOutput.DoctypePublic != null || _currentOutput.DoctypeSystem != null)
                                        _emitter.WriteDocType (prefix + (prefix==null? ":" : "") + localName, 
                                                _currentOutput.DoctypePublic, _currentOutput.DoctypeSystem);
                        }
@@ -230,7 +231,8 @@ namespace Mono.Xml.Xsl
                                _nsManager.AddNamespace (prefix, nsUri);
 
                        if (_currentNamespaceDecls [prefix] as string != nsUri) {
-                               _currentNsPrefixes.Add (prefix);
+                               if (!_currentNsPrefixes.Contains (prefix))
+                                       _currentNsPrefixes.Add (prefix);
                                _currentNamespaceDecls [prefix] = nsUri;
                        }
                }
index b907fd3f06155d9d98e3f599fbcdc72bb026deea..85c932dcf284e57e482a86058e552069763e0ad5 100644 (file)
@@ -26,6 +26,7 @@ namespace Mono.Xml.Xsl
                bool openAttribute;
                int xmlDepth;
                bool indent;
+               Encoding outputEncoding;
 
                public HtmlEmitter (TextWriter writer, XslOutput output)
                {
@@ -33,11 +34,11 @@ namespace Mono.Xml.Xsl
                        indent = !(output.Indent == "no");
                        elementNameStack = new Stack ();
                        xmlDepth = -1;
+                       outputEncoding = output.Encoding;
                }
 
                public override void WriteStartDocument (StandaloneType standalone)
                {
-                       // do nothing
                }
                
                public override void WriteEndDocument ()
@@ -47,19 +48,18 @@ namespace Mono.Xml.Xsl
 
                public override void WriteDocType (string name, string publicId, string systemId)
                {
-                       writer.Write ("<!DOCTYPE ");
-                       writer.Write (name);
-                       writer.Write (' ');
+                       writer.Write ("<!DOCTYPE html ");
                        if (publicId != null && publicId != String.Empty) {
-                               writer.Write ("PUBLIC ");
+                               writer.Write ("PUBLIC \"");
                                writer.Write (publicId);
-                               writer.Write (' ');
+                               writer.Write ("\" ");
                                writer.Write (systemId);
                        } else if (systemId != null && systemId != String.Empty) {
-                               writer.Write ("SYSTEM ");
+                               writer.Write ("SYSTEM \"");
                                writer.Write (systemId);
+                               writer.Write ('\"');
                        }
-                       writer.Write ('>');
+                       writer.Write (">\r\n");
                }
 
                private void CloseAttribute ()
@@ -74,6 +74,16 @@ namespace Mono.Xml.Xsl
                                CloseAttribute ();
                        writer.Write ('>');
                        openElement = false;
+
+                       if (outputEncoding != null && elementNameStack.Count > 0) {
+                               string name = elementNameStack.Peek () as string;
+                               if (name.ToUpper () == "HEAD") {
+                                       WriteStartElement (String.Empty, "META", String.Empty);
+                                       WriteAttributeString (String.Empty, "http-equiv", String.Empty, "Content-Type");
+                                       WriteAttributeString (String.Empty, "content", String.Empty, "text/html; charset=" + outputEncoding.WebName);
+                                       WriteEndElement ();
+                               }
+                       }
                }
 
                // FIXME: check all HTML elements' indentation.
@@ -166,7 +176,7 @@ namespace Mono.Xml.Xsl
                        case "COL":
                        case "FRAME":
                        case "HR":
-                       case "IMAGE":
+                       case "IMG":
                        case "INPUT":
                        case "ISINDEX":
                        case "LINK":
@@ -281,11 +291,6 @@ namespace Mono.Xml.Xsl
                                        writer.Write ("&lt;");
                                        start = i;
                                        break;
-                               case '>':
-                                       writer.Write (text.ToCharArray (), start, i - start);
-                                       writer.Write ("&gt;");
-                                       start = i;
-                                       break;
                                case '\'':
                                        writer.Write (text.ToCharArray (), start, i - start);
                                        writer.Write ("&apos;");
index cb87c1756c35473e2bdf0f82f3e58514dee85693..a4e0ba6fbd66bd02092bf292a5efd503dba542d1 100644 (file)
@@ -38,6 +38,7 @@ namespace Mono.Xml.Xsl {
 
                public override void WriteDocType (string type, string publicId, string systemId)
                {
+                       writer.WriteWhitespace (Environment.NewLine);
                        writer.WriteDocType (type, publicId, systemId, null);
                }
 
@@ -62,7 +63,13 @@ namespace Mono.Xml.Xsl {
                }               
 
                public override void WriteComment (string text) {
-                       writer.WriteComment (text);
+                       if (text.IndexOf ("--") >= 0)
+                               text = text.Replace ("--", "- -");
+
+                       if (text.EndsWith ("-"))
+                               writer.WriteComment (text + ' ');
+                       else
+                               writer.WriteComment (text);
                }
 
                public override void WriteProcessingInstruction (string name, string text)
index 2c05e68a6656efc38ffb043de3065d6e3a3374bf..f57f429cb5343ec13e6935704f9648c02c216795 100644 (file)
@@ -23,8 +23,6 @@ using QName = System.Xml.XmlQualifiedName;
 
 namespace Mono.Xml.Xsl {
        public class XslTransformProcessor {
-               static char [] wsChars = new char [] {' ', '\t', '\n', '\r'};
-
                CompiledStylesheet compiledStyle;
                
                XslStylesheet style;
@@ -477,8 +475,8 @@ namespace Mono.Xml.Xsl {
 
                public bool PushCDataState (string name, string ns)
                {
-                       if (insideCDataSectionElements)
-                               return false;
+//                     if (insideCDataSectionElements)
+//                             return false;
                        for (int i = 0; i < Output.CDataSectionElements.Length; i++) {
                                XmlQualifiedName qname = Output.CDataSectionElements [i];
                                if (qname.Name == name && qname.Namespace == ns) {
@@ -487,13 +485,19 @@ namespace Mono.Xml.Xsl {
                                        return true;
                                }
                        }
+                       this.insideCDataSectionElements = false;
+                       Out.InsideCDataSection = false; //
                        return false;
                }
 
-               public void PopCDataState ()
+               public void PopCDataState (bool isCData)
                {
-                       Out.InsideCDataSection = false;
-                       this.insideCDataSectionElements = false;
+                       Out.InsideCDataSection = this.insideCDataSectionElements = isCData;
+               }
+
+               public bool PreserveWhitespace ()
+               {
+                       return XPathContext.PreserveWhitespace (CurrentNode);
                }
        }
 }
index a1e3a7590d68600e8cf6b93e0554ed0b02bbe34d..fb8b7bd83216ccf7d7fdb6f7acd260a22df55889 100644 (file)
@@ -150,7 +150,36 @@ namespace Mono.Xml.Xsl {
                }
 
                public override int CompareDocument (string baseUri, string nextBaseUri) { throw new NotImplementedException (); }
-               public override bool PreserveWhitespace (XPathNavigator nav) { throw new NotImplementedException (); }
+
+               public override bool PreserveWhitespace (XPathNavigator nav) 
+               {
+                       XPathNavigator tmp = nav.Clone ();
+                       switch (tmp.NodeType) {
+                       case XPathNodeType.Root:
+                               return false;
+                       case XPathNodeType.Element:
+                               break;
+                       default:
+                               tmp.MoveToParent ();
+                               break;
+                       }
+
+                       for (; tmp.NodeType == XPathNodeType.Element; tmp.MoveToParent ()) {
+                               object o = p.CompiledStyle.Style.SpaceControls [new XmlQualifiedName (tmp.LocalName, tmp.NamespaceURI)];
+                               if (o == null)
+                                       continue;
+                               XmlSpace space = (XmlSpace) o;
+                               switch ((XmlSpace) o) {
+                               case XmlSpace.Preserve:
+                                       return true;
+                               case XmlSpace.Default:
+                                       return false;
+                               // None: continue.
+                               }
+                       }
+                       return true;
+               }
+
                public override bool Whitespace { get { throw new NotImplementedException (); }}
        }