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.IO;
2using System.Threading.Tasks;
3using System.Xml;
4using System.Xml.Xsl;
5using Waher.Script;
10
12{
17 {
27 : base(Xml, Xslt, Start, Length, Expression)
28 {
29 }
30
34 public override string FunctionName => nameof(Transform);
35
39 public override bool UpgradeScalarsToSameSet => false;
40
49 {
50 if (!(Argument1.AssociatedObjectValue is string s))
51 {
52 if (Argument1.AssociatedObjectValue is XmlDocument Xml)
53 s = Xml.OuterXml;
54 else
55 s = Expression.ToExpressionString(Argument1.AssociatedObjectValue);
56 }
57
58 if (!(Argument2.AssociatedObjectValue is XslCompiledTransform Xslt))
59 throw new ScriptRuntimeException("Second parameter must be an XSL Transform (XSLT) object.", this);
60
61 return this.DoTransform(s, Xslt);
62 }
63
72 {
73 return Task.FromResult<IElement>(this.EvaluateScalar(Argument1, Argument2, Variables));
74 }
75
76 private IElement DoTransform(string Xml, XslCompiledTransform Xslt)
77 {
78 return new StringValue(XSL.Transform(Xml, Xslt));
79 }
80
89 {
90 using (StringReader s = new StringReader(Argument2))
91 {
92 using (XmlReader r = XmlReader.Create(s))
93 {
94 XslCompiledTransform Xslt = new XslCompiledTransform();
95 Xslt.Load(r);
96
97 return this.DoTransform(Argument1, Xslt);
98 }
99 }
100 }
101
102 }
103}
override string FunctionName
Name of the function
Definition: Transform.cs:34
override Task< IElement > EvaluateScalarAsync(IElement Argument1, IElement Argument2, Variables Variables)
Evaluates the function on two scalar arguments.
Definition: Transform.cs:71
override bool UpgradeScalarsToSameSet
If scalars should be upgraded to the same set before evaluation.
Definition: Transform.cs:39
override IElement EvaluateScalar(IElement Argument1, IElement Argument2, Variables Variables)
Evaluates the function on two scalar arguments.
Definition: Transform.cs:48
Transform(ScriptNode Xml, ScriptNode Xslt, int Start, int Length, Expression Expression)
Transform(XML,XSLT)
Definition: Transform.cs:26
override IElement EvaluateScalar(string Argument1, string Argument2, Variables Variables)
Evaluates the function on two scalar arguments.
Definition: Transform.cs:88
Static class managing loading of XSL resources stored as embedded resources or in content files.
Definition: XSL.cs:16
static string Transform(string XML, XslCompiledTransform Transform)
Transforms an XML document using an XSL transform.
Definition: XSL.cs:197
Class managing a script expression.
Definition: Expression.cs:41
static string ToExpressionString(object Value)
Converts an object to a string, that can be parsed as part of an expression.
Definition: Expression.cs:5052
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:21