| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677 |
- //
- // System.Xml.XPath.DefaultContext & support classes
- //
- // Author:
- // Piers Haken ([email protected])
- //
- // (C) 2002 Piers Haken
- //
- using System;
- using System.Collections;
- using System.Xml;
- using System.Xml.XPath;
- using System.Xml.Xsl;
- namespace System.Xml.XPath
- {
- /// <summary>
- /// Summary description for DefaultContext.
- /// </summary>
- internal class DefaultContext : XsltContext
- {
- protected static Hashtable _htFunctions = new Hashtable ();
- static DefaultContext()
- {
- Add (new XPathFunctionLast ());
- Add (new XPathFunctionPosition ());
- Add (new XPathFunctionCount ());
- Add (new XPathFunctionId ());
- Add (new XPathFunctionLocalName ());
- Add (new XPathFunctionNamespaceUri ());
- Add (new XPathFunctionName ());
- Add (new XPathFunctionString ());
- Add (new XPathFunctionConcat ());
- Add (new XPathFunctionStartsWith ());
- Add (new XPathFunctionContains ());
- Add (new XPathFunctionSubstringBefore ());
- Add (new XPathFunctionSubstringAfter ());
- Add (new XPathFunctionSubstring ());
- Add (new XPathFunctionStringLength ());
- Add (new XPathFunctionNormalizeSpace ());
- Add (new XPathFunctionTranslate ());
- Add (new XPathFunctionBoolean ());
- Add (new XPathFunctionNot ());
- Add (new XPathFunctionTrue ());
- Add (new XPathFunctionFalse ());
- Add (new XPathFunctionLang ());
- Add (new XPathFunctionNumber ());
- Add (new XPathFunctionSum ());
- Add (new XPathFunctionFloor ());
- Add (new XPathFunctionCeil ());
- Add (new XPathFunctionRound ());
- }
- [MonoTODO]
- public override IXsltContextFunction ResolveFunction (string prefix, string name, XPathResultType[] ArgTypes)
- {
- // match the prefix
- if (prefix != null && prefix != "") // TODO: should we allow some namespaces here?
- return null;
- // match the function name
- XPathFunction fn = (XPathFunction) _htFunctions [name];
- if (fn == null)
- return null;
- // check the number of arguments
- int cArgs = ArgTypes.Length;
- if (cArgs < fn.Minargs || cArgs > fn.Maxargs)
- return null;
- // check the types of the arguments
- XPathResultType [] rgTypes = fn.ArgTypes;
- if (rgTypes == null)
- {
- if (cArgs != 0)
- return null;
- }
- else
- {
- int cTypes = rgTypes.Length;
- XPathResultType [] rgTypesRequested = ArgTypes;
- for (int iArg = 0; iArg < cArgs; iArg ++)
- {
- XPathResultType typeRequested = rgTypesRequested [iArg];
- XPathResultType typeDefined = (iArg >= cTypes) ? rgTypes [cTypes - 1] : rgTypes [iArg];
- if (typeRequested != XPathResultType.NodeSet &&
- typeDefined != XPathResultType.Any &&
- typeDefined != typeRequested)
- {
- return null;
- }
- }
- }
- return fn;
- }
- public override IXsltContextVariable ResolveVariable (string prefix, string name)
- {
- return null;
- }
- [MonoTODO]
- public override int CompareDocument (string baseUri, string nextBaseUri) { throw new NotImplementedException (); }
- [MonoTODO]
- public override bool PreserveWhitespace (XPathNavigator nav) { throw new NotImplementedException (); }
- [MonoTODO]
- public override bool Whitespace { get { throw new NotImplementedException (); }}
- protected static void Add (XPathFunction fn)
- {
- _htFunctions.Add (fn.Name, fn);
- }
- }
- internal class XPathFunctions
- {
- public static bool ToBoolean (object arg)
- {
- if (arg == null)
- throw new ArgumentNullException ();
- if (arg is bool)
- return (bool) arg;
- if (arg is double)
- {
- double dArg = (double) arg;
- return (dArg != 0.0 && !double.IsNaN (dArg));
- }
- if (arg is string)
- return ((string) arg).Length != 0;
- if (arg is BaseIterator)
- {
- BaseIterator iter = (BaseIterator) arg;
- return iter.MoveNext ();
- }
- throw new ArgumentException ();
- }
- [MonoTODO]
- public static string ToString (object arg)
- {
- if (arg == null)
- throw new ArgumentNullException ();
- if (arg is string)
- return (string) arg;
- if (arg is bool)
- return ((bool) arg) ? "true" : "false";
- if (arg is double)
- return ((double) arg).ToString ("R", System.Globalization.NumberFormatInfo.InvariantInfo);
- if (arg is BaseIterator)
- {
- BaseIterator iter = (BaseIterator) arg;
- if (!iter.MoveNext ())
- return "";
- return iter.Current.Value;
- }
- throw new ArgumentException ();
- }
- [MonoTODO]
- public static double ToNumber (object arg)
- {
- if (arg == null)
- throw new ArgumentNullException ();
- if (arg is BaseIterator)
- arg = ToString (arg); // follow on
- if (arg is string)
- return XmlConvert.ToDouble ((string) arg); // TODO: spec? convert string to number
- if (arg is double)
- return (double) arg;
- if (arg is bool)
- return Convert.ToDouble ((bool) arg);
- throw new ArgumentException ();
- }
- }
- internal abstract class XPathFunction : IXsltContextFunction
- {
- public abstract XPathResultType ReturnType { get; }
- public abstract int Minargs { get; }
- public abstract int Maxargs { get; }
- public abstract XPathResultType [] ArgTypes { get; }
- public object Invoke (XsltContext xsltContext, object[] args, XPathNavigator docContext)
- {
- return TypesafeInvoke (xsltContext, args, docContext);
- }
- public abstract string Name { get; }
- public abstract object TypesafeInvoke (XsltContext xsltContext, object[] args, XPathNavigator docContext);
- }
- internal class XPathFunctionLast : XPathFunction
- {
- public override XPathResultType ReturnType { get { return XPathResultType.Number; }}
- public override int Minargs { get { return 0; }}
- public override int Maxargs { get { return 0; }}
- public override XPathResultType [] ArgTypes { get { return null; }}
- public override object TypesafeInvoke (XsltContext xsltContext, object[] args, XPathNavigator docContext)
- {
- throw new NotImplementedException (); // special-cased
- }
- public override string Name { get { return "last"; }}
- }
- internal class XPathFunctionPosition : XPathFunction
- {
- public override XPathResultType ReturnType { get { return XPathResultType.Number; }}
- public override int Minargs { get { return 0; }}
- public override int Maxargs { get { return 0; }}
- public override XPathResultType [] ArgTypes { get { return null; }}
- public override object TypesafeInvoke (XsltContext xsltContext, object[] args, XPathNavigator docContext)
- {
- throw new NotImplementedException (); // special-cased
- }
- public override string Name { get { return "position"; }}
- }
- internal class XPathFunctionCount : XPathFunction
- {
- public override XPathResultType ReturnType { get { return XPathResultType.Number; }}
- public override int Minargs { get { return 1; }}
- public override int Maxargs { get { return 1; }}
- public override XPathResultType [] ArgTypes { get { return new XPathResultType [] { XPathResultType.NodeSet }; }}
- public override object TypesafeInvoke (XsltContext xsltContext, object[] args, XPathNavigator docContext)
- {
- return ((BaseIterator) args [0]).Count;
- }
- public override string Name { get { return "count"; }}
- }
- internal class XPathFunctionId : XPathFunction
- {
- private static char [] rgchWhitespace = {' ', '\t', '\r', '\n'};
- public override XPathResultType ReturnType { get { return XPathResultType.NodeSet; }}
- public override int Minargs { get { return 1; }}
- public override int Maxargs { get { return 1; }}
- public override XPathResultType [] ArgTypes { get { return new XPathResultType [] { XPathResultType.Any }; }}
- [MonoTODO]
- public override object TypesafeInvoke (XsltContext xsltContext, object[] args, XPathNavigator docContext)
- {
- String strArgs;
- BaseIterator iter = args [0] as BaseIterator;
- if (iter != null)
- {
- strArgs = "";
- while (!iter.MoveNext ())
- strArgs += iter.Current.Value + " ";
- }
- else
- strArgs = XPathFunctions.ToString (args [0]);
- string [] rgstrArgs = strArgs.Split (rgchWhitespace);
- ArrayList rgNodes = new ArrayList ();
- foreach (string strArg in rgstrArgs)
- {
- if (docContext.MoveToId (strArg))
- rgNodes.Add (docContext.Clone ());
- }
- return new ArrayListIterator (iter, rgNodes);
- }
- public override string Name { get { return "id"; }}
- }
- internal class XPathFunctionLocalName : XPathFunction
- {
- public override XPathResultType ReturnType { get { return XPathResultType.NodeSet; }}
- public override int Minargs { get { return 0; }}
- public override int Maxargs { get { return 1; }}
- public override XPathResultType [] ArgTypes { get { return new XPathResultType [] { XPathResultType.NodeSet }; }}
- public override object TypesafeInvoke (XsltContext xsltContext, object[] args, XPathNavigator docContext)
- {
- BaseIterator iter = (args.Length == 1) ? ((BaseIterator) args [0]) : new SelfIterator (docContext, xsltContext);
- if (iter == null || !iter.MoveNext ())
- return "";
- return iter.Current.LocalName;
- }
- public override string Name { get { return "local-name"; }}
- }
- internal class XPathFunctionNamespaceUri : XPathFunction
- {
- public override XPathResultType ReturnType { get { return XPathResultType.String; }}
- public override int Minargs { get { return 0; }}
- public override int Maxargs { get { return 1; }}
- public override XPathResultType [] ArgTypes { get { return new XPathResultType [] { XPathResultType.NodeSet }; }}
- [MonoTODO]
- public override object TypesafeInvoke (XsltContext xsltContext, object[] args, XPathNavigator docContext)
- {
- BaseIterator iter = (args.Length == 1) ? ((BaseIterator) args [0]) : new SelfIterator (docContext, xsltContext);
- if (iter == null || !iter.MoveNext ())
- return "";
- return iter.Current.NamespaceURI; // TODO: should the namespace be expanded wrt. the given context?
- }
- public override string Name { get { return "namespace-uri"; }}
- }
- internal class XPathFunctionName : XPathFunction
- {
- public override XPathResultType ReturnType { get { return XPathResultType.String; }}
- public override int Minargs { get { return 0; }}
- public override int Maxargs { get { return 1; }}
- public override XPathResultType [] ArgTypes { get { return new XPathResultType [] { XPathResultType.NodeSet }; }}
- [MonoTODO]
- public override object TypesafeInvoke (XsltContext xsltContext, object[] args, XPathNavigator docContext)
- {
- BaseIterator iter = (args.Length == 1) ? ((BaseIterator) args [0]) : new SelfIterator (docContext, xsltContext);
- if (iter == null || !iter.MoveNext ())
- return "";
- return iter.Current.Name;
- }
- public override string Name { get { return "name"; }}
- }
- internal class XPathFunctionString : XPathFunction
- {
- public override XPathResultType ReturnType { get { return XPathResultType.String; }}
- public override int Minargs { get { return 0; }}
- public override int Maxargs { get { return 1; }}
- public override XPathResultType [] ArgTypes { get { return new XPathResultType [] { XPathResultType.Any }; }}
- public override object TypesafeInvoke (XsltContext xsltContext, object[] args, XPathNavigator docContext)
- {
- return XPathFunctions.ToString (args [0]);
- }
- public override string Name { get { return "string"; }}
- }
- internal class XPathFunctionConcat : XPathFunction
- {
- public override XPathResultType ReturnType { get { return XPathResultType.String; }}
- public override int Minargs { get { return 2; }}
- public override int Maxargs { get { return int.MaxValue; }}
- public override XPathResultType [] ArgTypes { get { return new XPathResultType [] { XPathResultType.String, XPathResultType.String, XPathResultType.String }; }}
- public override object TypesafeInvoke (XsltContext xsltContext, object[] args, XPathNavigator docContext)
- {
- String str = "";
- foreach (string strArg in args)
- str += strArg;
- return str;
- }
- public override string Name { get { return "concat"; }}
- }
- internal class XPathFunctionStartsWith : XPathFunction
- {
- public override XPathResultType ReturnType { get { return XPathResultType.Boolean; }}
- public override int Minargs { get { return 2; }}
- public override int Maxargs { get { return 2; }}
- public override XPathResultType [] ArgTypes { get { return new XPathResultType [] { XPathResultType.String, XPathResultType.String }; }}
- public override object TypesafeInvoke (XsltContext xsltContext, object[] args, XPathNavigator docContext)
- {
- string str1 = (string) args [0];
- string str2 = (string) args [1];
- return str1.StartsWith (str2);
- }
- public override string Name { get { return "starts-with"; }}
- }
- internal class XPathFunctionContains : XPathFunction
- {
- public override XPathResultType ReturnType { get { return XPathResultType.Boolean; }}
- public override int Minargs { get { return 2; }}
- public override int Maxargs { get { return 2; }}
- public override XPathResultType [] ArgTypes { get { return new XPathResultType [] { XPathResultType.String, XPathResultType.String }; }}
- public override object TypesafeInvoke (XsltContext xsltContext, object[] args, XPathNavigator docContext)
- {
- string str1 = (string) args [0];
- string str2 = (string) args [1];
- return str1.IndexOf (str2) != -1;
- }
- public override string Name { get { return "contains"; }}
- }
- internal class XPathFunctionSubstringBefore : XPathFunction
- {
- public override XPathResultType ReturnType { get { return XPathResultType.String; }}
- public override int Minargs { get { return 2; }}
- public override int Maxargs { get { return 2; }}
- public override XPathResultType [] ArgTypes { get { return new XPathResultType [] { XPathResultType.String, XPathResultType.String }; }}
- public override object TypesafeInvoke (XsltContext xsltContext, object[] args, XPathNavigator docContext)
- {
- string str1 = (string) args [0];
- string str2 = (string) args [1];
- int ich = str1.IndexOf (str2);
- if (ich <= 0)
- return "";
- return str1.Substring (0, ich);
- }
- public override string Name { get { return "substring-before"; }}
- }
- internal class XPathFunctionSubstringAfter : XPathFunction
- {
- public override XPathResultType ReturnType { get { return XPathResultType.String; }}
- public override int Minargs { get { return 2; }}
- public override int Maxargs { get { return 2; }}
- public override XPathResultType [] ArgTypes { get { return new XPathResultType [] { XPathResultType.String, XPathResultType.String }; }}
- public override object TypesafeInvoke (XsltContext xsltContext, object[] args, XPathNavigator docContext)
- {
- string str1 = (string) args [0];
- string str2 = (string) args [1];
- int ich = str1.IndexOf (str2);
- if (ich <= 0)
- return "";
- return str1.Substring (ich + str2.Length);
- }
- public override string Name { get { return "substring-after"; }}
- }
- internal class XPathFunctionSubstring : XPathFunction
- {
- public override XPathResultType ReturnType { get { return XPathResultType.String; }}
- public override int Minargs { get { return 2; }}
- public override int Maxargs { get { return 3; }}
- public override XPathResultType [] ArgTypes { get { return new XPathResultType [] { XPathResultType.String, XPathResultType.Number, XPathResultType.Number }; }}
- [MonoTODO]
- public override object TypesafeInvoke (XsltContext xsltContext, object[] args, XPathNavigator docContext)
- {
- // TODO: check this, what the hell were they smoking?
- string str = (string) args [0];
- double ich = Math.Round ((double) args [1]) - 1;
- if (Double.IsNaN (ich) || ich >= (double) str.Length)
- return "";
- if (args.Length == 2)
- {
- if (ich < 0)
- ich = 0.0;
- return str.Substring ((int) ich);
- }
- else
- {
- double cch = Math.Round ((double) args [2]);
- if (Double.IsNaN (cch))
- return "";
- if (ich < 0.0 || cch < 0.0)
- {
- cch = ich + cch;
- if (cch <= 0.0)
- return "";
- ich = 0.0;
- }
- double cchMax = (double) str.Length - ich;
- if (cch > cchMax)
- cch = cchMax;
- return str.Substring ((int) ich, (int) cch);
- }
- }
- public override string Name { get { return "substring"; }}
- }
- internal class XPathFunctionStringLength : XPathFunction
- {
- public override XPathResultType ReturnType { get { return XPathResultType.Number; }}
- public override int Minargs { get { return 0; }}
- public override int Maxargs { get { return 1; }}
- public override XPathResultType [] ArgTypes { get { return new XPathResultType [] { XPathResultType.String }; }}
- public override object TypesafeInvoke (XsltContext xsltContext, object[] args, XPathNavigator docContext)
- {
- string str;
- if (args.Length == 1)
- str = (string) args [0];
- else
- str = docContext.Value;
- return (double) str.Length;
- }
- public override string Name { get { return "string-length"; }}
- }
- internal class XPathFunctionNormalizeSpace : XPathFunction
- {
- public override XPathResultType ReturnType { get { return XPathResultType.String; }}
- public override int Minargs { get { return 0; }}
- public override int Maxargs { get { return 1; }}
- public override XPathResultType [] ArgTypes { get { return new XPathResultType [] { XPathResultType.String }; }}
- [MonoTODO]
- public override object TypesafeInvoke (XsltContext xsltContext, object[] args, XPathNavigator docContext)
- {
- string str;
- if (args.Length == 1)
- str = (string) args [0];
- else
- str = docContext.Value;
- System.Text.StringBuilder sb = new System.Text.StringBuilder ();
- bool fSpace = false;
- foreach (char ch in str)
- {
- if (ch == ' ' || ch == '\t' || ch == '\r' || ch == '\n')
- {
- fSpace = true;
- }
- else
- {
- if (fSpace)
- {
- fSpace = false;
- if (sb.Length > 0)
- sb.Append (' ');
- }
- sb.Append (ch);
- }
- }
- return sb.ToString ();
- }
- public override string Name { get { return "normalize-space"; }}
- }
- internal class XPathFunctionTranslate : XPathFunction
- {
- public override XPathResultType ReturnType { get { return XPathResultType.String; }}
- public override int Minargs { get { return 3; }}
- public override int Maxargs { get { return 3; }}
- public override XPathResultType [] ArgTypes { get { return new XPathResultType [] { XPathResultType.String, XPathResultType.String, XPathResultType.String }; }}
- [MonoTODO]
- public override object TypesafeInvoke (XsltContext xsltContext, object[] args, XPathNavigator docContext)
- {
- throw new NotImplementedException ();
- }
- public override string Name { get { return "translate"; }}
- }
- internal class XPathFunctionBoolean : XPathFunction
- {
- public override XPathResultType ReturnType { get { return XPathResultType.Boolean; }}
- public override int Minargs { get { return 1; }}
- public override int Maxargs { get { return 1; }}
- public override XPathResultType [] ArgTypes { get { return new XPathResultType [] { XPathResultType.Any }; }}
- public override object TypesafeInvoke (XsltContext xsltContext, object[] args, XPathNavigator docContext)
- {
- return XPathFunctions.ToBoolean (args [0]);
- }
- public override string Name { get { return "boolean"; }}
- }
- internal class XPathFunctionNot : XPathFunction
- {
- public override XPathResultType ReturnType { get { return XPathResultType.Boolean; }}
- public override int Minargs { get { return 1; }}
- public override int Maxargs { get { return 1; }}
- public override XPathResultType [] ArgTypes { get { return new XPathResultType [] { XPathResultType.Any }; }}
- public override object TypesafeInvoke (XsltContext xsltContext, object[] args, XPathNavigator docContext)
- {
- return !(XPathFunctions.ToBoolean (args [0]));
- }
- public override string Name { get { return "not"; }}
- }
- internal class XPathFunctionTrue : XPathFunction
- {
- public override XPathResultType ReturnType { get { return XPathResultType.Boolean; }}
- public override int Minargs { get { return 0; }}
- public override int Maxargs { get { return 0; }}
- public override XPathResultType [] ArgTypes { get { return null; }}
- public override object TypesafeInvoke (XsltContext xsltContext, object[] args, XPathNavigator docContext)
- {
- return true;
- }
- public override string Name { get { return "true"; }}
- }
- internal class XPathFunctionFalse : XPathFunction
- {
- public override XPathResultType ReturnType { get { return XPathResultType.Boolean; }}
- public override int Minargs { get { return 0; }}
- public override int Maxargs { get { return 0; }}
- public override XPathResultType [] ArgTypes { get { return null; }}
- public override object TypesafeInvoke (XsltContext xsltContext, object[] args, XPathNavigator docContext)
- {
- return false;
- }
- public override string Name { get { return "false"; }}
- }
- internal class XPathFunctionLang : XPathFunction
- {
- public override XPathResultType ReturnType { get { return XPathResultType.Boolean; }}
- public override int Minargs { get { return 1; }}
- public override int Maxargs { get { return 1; }}
- public override XPathResultType [] ArgTypes { get { return new XPathResultType [] { XPathResultType.String }; }}
- [MonoTODO]
- public override object TypesafeInvoke (XsltContext xsltContext, object[] args, XPathNavigator docContext)
- {
- throw new NotImplementedException ();
- }
- public override string Name { get { return "lang"; }}
- }
- internal class XPathFunctionNumber : XPathFunction
- {
- public override XPathResultType ReturnType { get { return XPathResultType.Number; }}
- public override int Minargs { get { return 0; }}
- public override int Maxargs { get { return 1; }}
- public override XPathResultType [] ArgTypes { get { return new XPathResultType [] { XPathResultType.Any }; }}
- public override object TypesafeInvoke (XsltContext xsltContext, object[] args, XPathNavigator docContext)
- {
- return XPathFunctions.ToNumber (args [0]);
- }
- public override string Name { get { return "number"; }}
- }
- internal class XPathFunctionSum : XPathFunction
- {
- public override XPathResultType ReturnType { get { return XPathResultType.Number; }}
- public override int Minargs { get { return 1; }}
- public override int Maxargs { get { return 1; }}
- public override XPathResultType [] ArgTypes { get { return new XPathResultType [] { XPathResultType.NodeSet }; }}
- [MonoTODO]
- public override object TypesafeInvoke (XsltContext xsltContext, object[] args, XPathNavigator docContext)
- {
- throw new NotImplementedException ();
- }
- public override string Name { get { return "sum"; }}
- }
- internal class XPathFunctionFloor : XPathFunction
- {
- public override XPathResultType ReturnType { get { return XPathResultType.Number; }}
- public override int Minargs { get { return 1; }}
- public override int Maxargs { get { return 1; }}
- public override XPathResultType [] ArgTypes { get { return new XPathResultType [] { XPathResultType.Number }; }}
- public override object TypesafeInvoke (XsltContext xsltContext, object[] args, XPathNavigator docContext)
- {
- return Math.Floor ((double) args [0]);
- }
- public override string Name { get { return "floor"; }}
- }
- internal class XPathFunctionCeil : XPathFunction
- {
- public override XPathResultType ReturnType { get { return XPathResultType.Number; }}
- public override int Minargs { get { return 1; }}
- public override int Maxargs { get { return 1; }}
- public override XPathResultType [] ArgTypes { get { return new XPathResultType [] { XPathResultType.Number }; }}
- public override object TypesafeInvoke (XsltContext xsltContext, object[] args, XPathNavigator docContext)
- {
- return Math.Ceiling ((double) args [0]);
- }
- public override string Name { get { return "ceil"; }}
- }
- internal class XPathFunctionRound : XPathFunction
- {
- public override XPathResultType ReturnType { get { return XPathResultType.Number; }}
- public override int Minargs { get { return 1; }}
- public override int Maxargs { get { return 1; }}
- public override XPathResultType [] ArgTypes { get { return new XPathResultType [] { XPathResultType.Number }; }}
- public override object TypesafeInvoke (XsltContext xsltContext, object[] args, XPathNavigator docContext)
- {
- double arg = (double) args [0];
- if (arg < -0.5 || arg > 0)
- return Math.Floor (arg + 0.5);
- return Math.Round (arg);
- }
- public override string Name { get { return "round"; }}
- }
- }
|