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
15 // Permission is hereby granted, free of charge, to any person obtaining
16 // a copy of this software and associated documentation files (the
17 // "Software"), to deal in the Software without restriction, including
18 // without limitation the rights to use, copy, modify, merge, publish,
19 // distribute, sublicense, and/or sell copies of the Software, and to
20 // permit persons to whom the Software is furnished to do so, subject to
21 // the following conditions:
23 // The above copyright notice and this permission notice shall be
24 // included in all copies or substantial portions of the Software.
26 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
27 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
28 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
29 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
30 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
31 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
32 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
36 using System
.Collections
;
38 using System
.Xml
.Schema
;
39 using System
.Xml
.XPath
;
43 namespace Mono
.Xml
.Xsl
45 using QName
= System
.Xml
.XmlQualifiedName
;
47 internal enum OutputMethod
{
55 internal enum StandaloneType
{
61 internal class XslOutput
// also usable for xsl:result-document
65 OutputMethod method
= OutputMethod
.Unknown
;
67 Encoding encoding
= System
.Text
.Encoding
.UTF8
;
68 bool omitXmlDeclaration
;
69 StandaloneType standalone
= StandaloneType
.NONE
;
72 QName
[] cdataSectionElements
;
75 bool escapeUriAttributes
;
76 bool includeContentType
;
77 bool normalizeUnicode
;
78 bool undeclareNamespaces
;
79 QName
[] useCharacterMaps
;
81 // for compilation only.
82 ArrayList cdSectsList
= new ArrayList ();
84 public XslOutput (string uri
)
89 public OutputMethod Method { get { return method; }}
90 public QName CustomMethod { get { return customMethod; }}
92 public string Version
{
93 get { return version; }
96 public Encoding Encoding
{
97 get { return encoding; }
104 public bool OmitXmlDeclaration
{
105 get { return omitXmlDeclaration; }
108 public StandaloneType Standalone
{
109 get { return standalone; }
112 public string DoctypePublic
{
113 get { return doctypePublic; }
116 public string DoctypeSystem
{
117 get { return doctypeSystem; }
120 public QName
[] CDataSectionElements
{
122 if (cdataSectionElements
== null)
123 cdataSectionElements
= cdSectsList
.ToArray (typeof (QName
)) as QName
[];
124 return cdataSectionElements
;
128 public string Indent
{
129 get { return indent; }
132 public string MediaType
{
133 get { return mediaType; }
136 // Below are introduced in XSLT 2.0 (WD-20030502)
137 public bool EscapeUriAttributes
{
138 get { return escapeUriAttributes; }
141 public bool IncludeContentType
{
142 get { return includeContentType; }
145 public bool NormalizeUnicode
{
146 get { return normalizeUnicode; }
149 public bool UndeclareNamespaces
{
150 get { return undeclareNamespaces; }
153 public QName
[] UseCharacterMaps
{
154 get { return useCharacterMaps; }
157 public void Fill (XPathNavigator nav
)
161 att
= nav
.GetAttribute ("cdata-section-elements", "");
162 if (att
!= String
.Empty
)
163 cdSectsList
.AddRange (XslNameUtil
.FromListString (att
, nav
));
165 att
= nav
.GetAttribute ("method", "");
167 if (att
!= String
.Empty
) {
170 method
= OutputMethod
.XML
;
173 method
= OutputMethod
.HTML
;
176 method
= OutputMethod
.Text
;
179 method
= OutputMethod
.Custom
;
180 customMethod
= XslNameUtil
.FromString (att
, nav
);
181 if (customMethod
.Namespace
== String
.Empty
) {
182 IXmlLineInfo li
= nav
as IXmlLineInfo
;
183 throw new XsltCompileException (new ArgumentException ("Invalid output method value: '" + att
+
184 "'. It must be either 'xml' or 'html' or 'text' or QName."),
186 li
!= null ? li
.LineNumber
: 0,
187 li
!= null ? li
.LinePosition
: 0);
193 att
= nav
.GetAttribute ("version", "");
194 if (att
!= String
.Empty
)
197 att
= nav
.GetAttribute ("encoding", "");
198 if (att
!= String
.Empty
)
199 this.encoding
= System
.Text
.Encoding
.GetEncoding (att
);
201 att
= nav
.GetAttribute ("standalone", "");
202 if (att
!= String
.Empty
)
203 //TODO: Should we validate values?
204 this.standalone
= att
== "yes" ? StandaloneType
.YES
: StandaloneType
.NO
;
207 att
= nav
.GetAttribute ("doctype-public", "");
208 if (att
!= String
.Empty
)
209 this.doctypePublic
= att
;
211 att
= nav
.GetAttribute ("doctype-system", "");
212 if (att
!= String
.Empty
)
213 this.doctypeSystem
= att
;
215 att
= nav
.GetAttribute ("media-type", "");
216 if (att
!= String
.Empty
)
217 this.mediaType
= att
;
219 att
= nav
.GetAttribute ("omit-xml-declaration", "");
220 if (att
!= String
.Empty
)
221 this.omitXmlDeclaration
= att
== "yes";
223 att
= nav
.GetAttribute ("indent", "");
224 if (att
!= String
.Empty
)