2004-02-06 Atsushi Enomoto <atsushi@ximian.com>
[mono.git] / mcs / class / System.XML / Mono.Xml.Xsl.Operations / XslText.cs
1 //
2 // XslText.cs
3 //
4 // Authors:
5 //      Ben Maurer (bmaurer@users.sourceforge.net)
6 //      Atsushi Enomoto (ginga@kit.hi-ho.ne.jp)
7 //      
8 // (C) 2003 Ben Maurer
9 // (C) 2003 Atsushi Enomoto
10 //
11
12 using System;
13 using System.Collections;
14 using System.Xml;
15 using System.Xml.XPath;
16 using System.Xml.Xsl;
17
18 namespace Mono.Xml.Xsl.Operations {
19         public class XslText : XslCompiledElement {
20                 bool disableOutputEscaping = false;
21                 string text = "";
22                 bool isWhitespace;
23                 
24                 public XslText (Compiler c, bool isWhitespace) : base (c)
25                 {
26                         this.isWhitespace = isWhitespace;
27                 }
28
29                 protected override void Compile (Compiler c)
30                 {
31                         this.text = c.Input.Value;
32                         
33                         if (c.Input.NodeType == XPathNodeType.Element)
34                                 this.disableOutputEscaping = c.ParseYesNoAttribute ("disable-output-escaping", false);
35                 }
36                 
37
38                 public override void Evaluate (XslTransformProcessor p)
39                 {
40                         if (isWhitespace && !p.PreserveWhitespace ())
41                                 return; // write nothing
42                         if (!disableOutputEscaping) {
43                                 if (isWhitespace)
44                                         p.Out.WriteWhitespace (text);
45                                 else
46                                         p.Out.WriteString (text);
47                         }
48                         else
49                                 p.Out.WriteRaw (text);
50                 }
51         }
52 }