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); }
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); }
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()); } }
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; }
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; }
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; }
/// <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); }
/// <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)); }
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); }
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); } }
/// <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; }
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); }
/// <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); }
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; }
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; }
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(); } }
/// <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);
protected override object Invoke(EvaluationXsltContext context, XPathNavigator navigator, params object[] args) { return(DateTime.UtcNow.ToString("yyyy-MM-ddThh:mm:ssZ")); }
protected override object Invoke(EvaluationXsltContext context, XPathNavigator navigator, params object[] args) { return context.EvaluationContext.Position; }
protected override object Invoke(EvaluationXsltContext context, XPathNavigator navigator, params object[] args) { return(context.EvaluationContext.Position); }
protected override object Invoke(EvaluationXsltContext context, XPathNavigator navigator, params object[] args) { return DateTime.UtcNow.ToString("yyyy-MM-ddThh:mm:ssZ"); }