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.UTF8;
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;
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 // cdata-section-elements
143 // att = nav.GetAttribute ("cdata-section-elements", "");
145 // cdSectsList.AddRange (XslNameUtil.ParseQNames (att, nav));
147 att = nav.GetAttribute ("method", "");
149 if (att != String.Empty) {
152 method = OutputMethod.XML;
155 method = OutputMethod.HTML;
158 method = OutputMethod.Text;
161 method = OutputMethod.Custom;
162 customMethod = XslNameUtil.FromString (att, nav);
163 if (customMethod.Namespace == String.Empty)
164 //TODO: how to get current line number and position?
165 throw new XsltCompileException(new ArgumentException("Invalid output method value: '" + att +
166 "'. It must be either 'xml' or 'html' or 'text' or QName."), nav.BaseURI, 1, 1);
171 att = nav.GetAttribute ("version", "");
172 if (att != String.Empty)
175 att = nav.GetAttribute ("encoding", "");
176 if (att != String.Empty)
177 this.encoding = System.Text.Encoding.GetEncoding (att);
179 att = nav.GetAttribute ("standalone", "");
180 if (att != String.Empty)
181 //TODO: Should we validate values?
182 this.standalone = att == "yes" ? StandaloneType.YES : StandaloneType.NO;
185 att = nav.GetAttribute ("doctype-public", "");
186 if (att != String.Empty)
187 this.doctypePublic = att;
189 att = nav.GetAttribute ("doctype-system", "");
190 if (att != String.Empty)
191 this.doctypeSystem = att;
193 att = nav.GetAttribute ("media-type", "");
194 if (att != String.Empty)
195 this.mediaType = att;
197 att = nav.GetAttribute ("omit-xml-declaration", "");
198 if (att != String.Empty)
199 this.omitXmlDeclaration = att == "yes";
201 att = nav.GetAttribute ("indent", "");
202 if (att != String.Empty)
203 this.indent = att == "yes";