Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
Transform.cs
1using System;
2using System.IO;
3using System.Threading.Tasks;
4using System.Xml;
5using System.Xml.Xsl;
6using Waher.Script;
11
13{
18 {
28 : base(Xml, Xslt, Start, Length, Expression)
29 {
30 }
31
35 public override string FunctionName => nameof(Transform);
36
45 {
46 if (!(Argument1.AssociatedObjectValue is string s))
47 {
48 if (Argument1.AssociatedObjectValue is XmlDocument Xml)
49 s = Xml.OuterXml;
50 else
51 s = Expression.ToString(Argument1.AssociatedObjectValue);
52 }
53
54 if (!(Argument2.AssociatedObjectValue is XslCompiledTransform Xslt))
55 throw new ScriptRuntimeException("Second parameter must be an XSL Transform (XSLT) object.", this);
56
57 return this.DoTransform(s, Xslt);
58 }
59
68 {
69 return Task.FromResult<IElement>(this.EvaluateScalar(Argument1, Argument2, Variables));
70 }
71
72 private IElement DoTransform(string Xml, XslCompiledTransform Xslt)
73 {
74 return new StringValue(XSL.Transform(Xml, Xslt));
75 }
76
85 {
86 using (StringReader s = new StringReader(Argument2))
87 {
88 using (XmlReader r = XmlReader.Create(s))
89 {
90 XslCompiledTransform Xslt = new XslCompiledTransform();
91 Xslt.Load(r);
92
93 return this.DoTransform(Argument1, Xslt);
94 }
95 }
96 }
97
98 }
99}
override string FunctionName
Name of the function
Definition: Transform.cs:35
override Task< IElement > EvaluateScalarAsync(IElement Argument1, IElement Argument2, Variables Variables)
Evaluates the function on two scalar arguments.
Definition: Transform.cs:67
override IElement EvaluateScalar(IElement Argument1, IElement Argument2, Variables Variables)
Evaluates the function on two scalar arguments.
Definition: Transform.cs:44
Transform(ScriptNode Xml, ScriptNode Xslt, int Start, int Length, Expression Expression)
Transform(XML,XSLT)
Definition: Transform.cs:27
override IElement EvaluateScalar(string Argument1, string Argument2, Variables Variables)
Evaluates the function on two scalar arguments.
Definition: Transform.cs:84
Static class managing loading of XSL resources stored as embedded resources or in content files.
Definition: XSL.cs:15
static string Transform(string XML, XslCompiledTransform Transform)
Transforms an XML document using an XSL transform.
Definition: XSL.cs:162
Class managing a script expression.
Definition: Expression.cs:39
static string ToString(double Value)
Converts a value to a string, that can be parsed as part of an expression.
Definition: Expression.cs:4496
Base class for funcions of two scalar variables.
ScriptNode Argument2
Function argument 2.
ScriptNode Argument1
Function argument 1.
Base class for all nodes in a parsed script tree.
Definition: ScriptNode.cs:69
int Length
Length of expression covered by node.
Definition: ScriptNode.cs:101
int Start
Start position in script expression.
Definition: ScriptNode.cs:92
Collection of variables.
Definition: Variables.cs:25
Basic interface for all types of elements.
Definition: IElement.cs:20