5 // Ben Maurer (bmaurer@users.sourceforge.net)
6 // Atsushi Enomoto (ginga@kit.hi-ho.ne.jp)
7 // Oleg Tkachenko (oleg@tkachenko.com)
10 // (C) 2003 Atsushi Enomoto
11 // (C) 2003 Oleg Tkachenko
16 using System.Collections;
18 using System.Xml.Schema;
19 using System.Xml.XPath;
23 namespace Mono.Xml.Xsl
25 using QName = System.Xml.XmlQualifiedName;
27 public enum OutputMethod {
35 public enum StandaloneType {
41 public class XslOutput // also usable for xsl:result-document
45 OutputMethod method = OutputMethod.Unknown;
47 Encoding encoding = System.Text.Encoding.Unicode;
48 bool omitXmlDeclaration;
49 StandaloneType standalone = StandaloneType.NONE;
52 QName [] cdataSectionElements;
55 bool escapeUriAttributes;
56 bool includeContentType;
57 bool normalizeUnicode;
58 bool undeclareNamespaces;
59 QName [] useCharacterMaps;
61 // for compilation only.
62 ArrayList cdSectsList = new ArrayList ();
64 public XslOutput (string uri)
69 public OutputMethod Method { get { return method; }}
70 public QName CustomMethod { get { return customMethod; }}
72 public string Version {
73 get { return version; }
76 public Encoding Encoding {
77 get { return encoding; }
84 public bool OmitXmlDeclaration {
85 get { return omitXmlDeclaration; }
88 public StandaloneType Standalone {
89 get { return standalone; }
92 public string DoctypePublic {
93 get { return doctypePublic; }
96 public string DoctypeSystem {
97 get { return doctypeSystem; }
100 public QName [] CDataSectionElements {
102 if (cdataSectionElements == null)
103 cdataSectionElements = cdSectsList.ToArray (typeof (QName)) as QName [];
104 return cdataSectionElements;
108 public string Indent {
109 get { return indent; }
112 public string MediaType {
113 get { return mediaType; }
116 // Below are introduced in XSLT 2.0 (WD-20030502)
117 public bool EscapeUriAttributes {
118 get { return escapeUriAttributes; }
121 public bool IncludeContentType {
122 get { return includeContentType; }
125 public bool NormalizeUnicode {
126 get { return normalizeUnicode; }
129 public bool UndeclareNamespaces {
130 get { return undeclareNamespaces; }
133 public QName [] UseCharacterMaps {
134 get { return useCharacterMaps; }
137 public void Fill (XPathNavigator nav)
141 att = nav.GetAttribute ("cdata-section-elements", "");
142 if (att != String.Empty)
143 cdSectsList.AddRange (XslNameUtil.FromListString (att, nav));
145 att = nav.GetAttribute ("method", "");
147 if (att != String.Empty) {
150 method = OutputMethod.XML;
153 method = OutputMethod.HTML;
156 method = OutputMethod.Text;
159 method = OutputMethod.Custom;
160 customMethod = XslNameUtil.FromString (att, nav);
161 if (customMethod.Namespace == String.Empty)
162 //TODO: how to get current line number and position?
163 throw new XsltCompileException(new ArgumentException("Invalid output method value: '" + att +
164 "'. It must be either 'xml' or 'html' or 'text' or QName."), nav.BaseURI, 1, 1);
169 att = nav.GetAttribute ("version", "");
170 if (att != String.Empty)
173 att = nav.GetAttribute ("encoding", "");
174 if (att != String.Empty)
175 this.encoding = System.Text.Encoding.GetEncoding (att);
177 att = nav.GetAttribute ("standalone", "");
178 if (att != String.Empty)
179 //TODO: Should we validate values?
180 this.standalone = att == "yes" ? StandaloneType.YES : StandaloneType.NO;
183 att = nav.GetAttribute ("doctype-public", "");
184 if (att != String.Empty)
185 this.doctypePublic = att;
187 att = nav.GetAttribute ("doctype-system", "");
188 if (att != String.Empty)
189 this.doctypeSystem = att;
191 att = nav.GetAttribute ("media-type", "");
192 if (att != String.Empty)
193 this.mediaType = att;
195 att = nav.GetAttribute ("omit-xml-declaration", "");
196 if (att != String.Empty)
197 this.omitXmlDeclaration = att == "yes";
199 att = nav.GetAttribute ("indent", "");
200 if (att != String.Empty)