Example #1
0
        protected override object Invoke(EvaluationXsltContext context, XPathNavigator navigator, params object[] args)
        {
            var nodes = args[0] as XPathNodeIterator;

            if (nodes == null)
            {
                return(double.NaN);
            }

            double current = double.MinValue;

            foreach (var node in nodes)
            {
                double value = double.MinValue;
                if (node is XElement && !double.TryParse(((XElement)node).Value, out value) ||
                    node is XAttribute && !double.TryParse(((XAttribute)node).Value, out value))
                {
                    continue;
                }

                if (current < value)
                {
                    current = value;
                }
            }

            return(current != double.MinValue ? current : double.NaN);
        }
Example #2
0
        protected override object Invoke(EvaluationXsltContext context, XPathNavigator navigator, params object[] args)
        {
            var idRef = (IdRef)(string)args[0];

            if (idRef == null)
            {
                return(double.NaN);
            }

            var element = context.Xml.ResolveId(idRef);

            if (element == null)
            {
                return(double.NaN);
            }

            var repeat = element.InterfaceOrDefault <Repeat>();

            if (repeat == null)
            {
                return(double.NaN);
            }

            return((double)repeat.Index);
        }
Example #3
0
        protected override object Invoke(EvaluationXsltContext context, XPathNavigator navigator, params object[] args)
        {
            var id = args.Length > 0 ? ((string)args[0]).TrimToNull() : null;

            if (id == null)
            {
                return(GetModel(context, navigator).Instances
                       .Select(i => i.State.Document.Root.CreateNavigator().Select("."))
                       .FirstOrDefault());
            }
            else
            {
                // resolve instance based on id
                var instance = context.Xml.ResolveId(id);
                if (instance == null)
                {
                    throw new DOMTargetEventException(context.Xml.Parent, Events.BindingException,
                                                      string.Format("Unresolved instance IDREF '{0}'.", id));
                }

                return(instance
                       .Interfaces <Instance>()
                       .Select(i => i.State.Document)
                       .Where(i => i != null)
                       .Select(i => i.Root.CreateNavigator().Select("."))
                       .FirstOrDefault());
            }
        }
Example #4
0
 protected override object Invoke(EvaluationXsltContext context, XPathNavigator navigator, params object[] args)
 {
     bool result;
     if (bool.TryParse(args[0].ToString(), out result))
         return result;
     else
         return false;
 }
Example #5
0
        protected override object Invoke(EvaluationXsltContext context, XPathNavigator navigator, params object[] args)
        {
            DateTime d;
            if (!DateTime.TryParse((string)args[0], out d))
                return double.NaN;

            return (d - new DateTime(1970, 1, 1)).TotalDays;
        }
Example #6
0
 protected override object Invoke(EvaluationXsltContext context, XPathNavigator navigator, params object[] args)
 {
     if (args.Length >= 2 &&
         args[0] as bool? == true)
         return args[1];
     else if (args.Length >= 3)
         return args[2];
     return null;
 }
Example #7
0
        /// <summary>
        /// Gets the current instance of the navigator.
        /// </summary>
        /// <param name="context"></param>
        /// <param name="navigator"></param>
        /// <returns></returns>
        protected Instance GetInstance(EvaluationXsltContext context, XPathNavigator navigator)
        {
            Contract.Requires<ArgumentNullException>(context != null);
            Contract.Requires<ArgumentNullException>(navigator != null);
            Contract.Requires<ArgumentNullException>(navigator.UnderlyingObject != null);
            Contract.Requires<ArgumentNullException>(navigator.UnderlyingObject is XObject);

            return GetInstance(navigator);
        }
Example #8
0
        /// <summary>
        /// Gets the current instance of the navigator.
        /// </summary>
        /// <param name="context"></param>
        /// <param name="navigator"></param>
        /// <returns></returns>
        protected Instance GetInstance(EvaluationXsltContext context, XPathNavigator navigator)
        {
            Contract.Requires <ArgumentNullException>(context != null);
            Contract.Requires <ArgumentNullException>(navigator != null);
            Contract.Requires <ArgumentNullException>(navigator.UnderlyingObject != null);
            Contract.Requires <ArgumentNullException>(navigator.UnderlyingObject is XObject);

            return(GetInstance(navigator));
        }
Example #9
0
        protected override object Invoke(EvaluationXsltContext context, XPathNavigator navigator, params object[] args)
        {
            DateTime d;

            if (!DateTime.TryParse((string)args[0], out d))
            {
                return(double.NaN);
            }

            return((d - new DateTime(1970, 1, 1)).TotalDays);
        }
Example #10
0
        protected override object Invoke(EvaluationXsltContext context, XPathNavigator navigator, params object[] args)
        {
            bool result;

            if (bool.TryParse(args[0].ToString(), out result))
            {
                return(result);
            }
            else
            {
                return(false);
            }
        }
Example #11
0
        /// <summary>
        /// Gets the current model of the navigator.
        /// </summary>
        /// <param name="context"></param>
        /// <param name="navigator"></param>
        /// <returns></returns>
        protected Model GetModel(EvaluationXsltContext context, XPathNavigator navigator)
        {
            Contract.Requires<ArgumentNullException>(context != null);
            Contract.Requires<ArgumentNullException>(navigator != null);
            Contract.Requires<ArgumentNullException>(navigator.UnderlyingObject != null);
            Contract.Requires<ArgumentNullException>(navigator.UnderlyingObject is XObject);

            var result = GetModel(navigator);
            if (result == null)
                throw new NullReferenceException();

            return result;
        }
Example #12
0
 protected override object Invoke(EvaluationXsltContext context, XPathNavigator navigator, params object[] args)
 {
     if (args.Length >= 2 &&
         args[0] as bool? == true)
     {
         return(args[1]);
     }
     else if (args.Length >= 3)
     {
         return(args[2]);
     }
     return(null);
 }
Example #13
0
        /// <summary>
        /// Gets the current model of the navigator.
        /// </summary>
        /// <param name="context"></param>
        /// <param name="navigator"></param>
        /// <returns></returns>
        protected Model GetModel(EvaluationXsltContext context, XPathNavigator navigator)
        {
            Contract.Requires <ArgumentNullException>(context != null);
            Contract.Requires <ArgumentNullException>(navigator != null);
            Contract.Requires <ArgumentNullException>(navigator.UnderlyingObject != null);
            Contract.Requires <ArgumentNullException>(navigator.UnderlyingObject is XObject);

            var result = GetModel(navigator);

            if (result == null)
            {
                throw new NullReferenceException();
            }

            return(result);
        }
Example #14
0
        protected override object Invoke(EvaluationXsltContext context, XPathNavigator navigator, params object[] args)
        {
            var idRef = (IdRef)(string)args[0];
            if (idRef == null)
                return double.NaN;

            var element = context.Xml.ResolveId(idRef);
            if (element == null)
                return double.NaN;

            var repeat = element.InterfaceOrDefault<Repeat>();
            if (repeat == null)
                return double.NaN;

            return (double)repeat.Index;
        }
Example #15
0
        protected override object Invoke(EvaluationXsltContext context, XPathNavigator navigator, params object[] args)
        {
            var nodes = args[0] as XPathNodeIterator;
            if (nodes == null)
                return double.NaN;

            double current = double.MinValue;
            foreach (var node in nodes)
            {
                double value = double.MinValue;
                if (node is XElement && !double.TryParse(((XElement)node).Value, out value) ||
                    node is XAttribute && !double.TryParse(((XAttribute)node).Value, out value))
                    continue;

                if (current < value)
                    current = value;
            }

            return current != double.MinValue ? current : double.NaN;
        }
Example #16
0
        protected override object Invoke(EvaluationXsltContext context, XPathNavigator navigator, params object[] args)
        {
            var id = args.Length > 0 ? ((string)args[0]).TrimToNull() : null;
            if (id == null)
                return GetModel(context, navigator).Instances
                    .Select(i => i.State.Document.Root.CreateNavigator().Select("."))
                    .FirstOrDefault();
            else
            {
                // resolve instance based on id
                var instance = context.Xml.ResolveId(id);
                if (instance == null)
                    throw new DOMTargetEventException(context.Xml.Parent, Events.BindingException,
                        string.Format("Unresolved instance IDREF '{0}'.", id));

                return instance
                    .Interfaces<Instance>()
                    .Select(i => i.State.Document)
                    .Where(i => i != null)
                    .Select(i => i.Root.CreateNavigator().Select("."))
                    .FirstOrDefault();
            }
        }
Example #17
0
 /// <summary>
 /// Implement this method to provide function implementation.
 /// </summary>
 /// <param name="args"></param>
 /// <returns></returns>
 protected abstract object Invoke(EvaluationXsltContext context, XPathNavigator navigator, params object[] args);
Example #18
0
 protected override object Invoke(EvaluationXsltContext context, XPathNavigator navigator, params object[] args)
 {
     return(DateTime.UtcNow.ToString("yyyy-MM-ddThh:mm:ssZ"));
 }
Example #19
0
 protected override object Invoke(EvaluationXsltContext context, XPathNavigator navigator, params object[] args)
 {
     return context.EvaluationContext.Position;
 }
Example #20
0
 protected override object Invoke(EvaluationXsltContext context, XPathNavigator navigator, params object[] args)
 {
     return(context.EvaluationContext.Position);
 }
Example #21
0
 /// <summary>
 /// Implement this method to provide function implementation.
 /// </summary>
 /// <param name="args"></param>
 /// <returns></returns>
 protected abstract object Invoke(EvaluationXsltContext context, XPathNavigator navigator, params object[] args);
Example #22
0
 protected override object Invoke(EvaluationXsltContext context, XPathNavigator navigator, params object[] args)
 {
     return DateTime.UtcNow.ToString("yyyy-MM-ddThh:mm:ssZ");
 }