/// <summary> /// Implements the following function /// node-set highest(node-set) /// </summary> /// <param name="iterator">The input nodeset</param> /// <returns>All the nodes that contain the max value in the nodeset</returns> public static XPathNodeIterator highest(XPathNodeIterator iterator){ ExsltNodeList newList = new ExsltNodeList(); double max, t; if(iterator.Count == 0){ return ExsltCommon.ExsltNodeListToXPathNodeIterator(newList); } try{ iterator.MoveNext(); max = XmlConvert.ToDouble(iterator.Current.Value); newList.Add(iterator.Current.Clone()); while (iterator.MoveNext()){ t = XmlConvert.ToDouble(iterator.Current.Value); if(t > max){ max = t; newList.Clear(); newList.Add(iterator.Current.Clone()); }else if( t == max){ newList.Add(iterator.Current.Clone()); } } }catch(Exception){ //return empty node set newList.Clear(); return ExsltCommon.ExsltNodeListToXPathNodeIterator(newList); } return ExsltCommon.ExsltNodeListToXPathNodeIterator(newList); }
/// <summary> /// Implements the following function /// node-set trailing(node-set, node-set) /// </summary> /// <param name="nodeset1"></param> /// <param name="nodeset2"></param> /// <returns>returns the nodes in the node set passed as the /// first argument that follow, in document order, the first node /// in the node set passed as the second argument</returns> public static XPathNodeIterator trailing(XPathNodeIterator nodeset1, XPathNodeIterator nodeset2) { XPathNavigator leader = null; if (nodeset2.MoveNext()) { leader = nodeset2.Current; } else { return(nodeset1); } ExsltNodeList nodelist1 = new ExsltNodeList(); while (nodeset1.MoveNext()) { if (nodeset1.Current.ComparePosition(leader) == XmlNodeOrder.After) { nodelist1.Add(nodeset1.Current.Clone()); } } return(ExsltCommon.ExsltNodeListToXPathNodeIterator(nodelist1)); }
} /* objecttype(object) */ /// <summary> /// This method converts an ExsltNodeList to an XPathNodeIterator over the nodes in the list. /// </summary> /// <param name="list">The list to convert</param> /// <returns>An XPathNodeIterator over the nodes in the original list</returns> /// <remarks>Known Issues: A node list containing multiple instances of an attribute /// with the same namespace name and local name will cause an error.</remarks> internal static XPathNodeIterator ExsltNodeListToXPathNodeIterator(ExsltNodeList list) { Assembly systemXml = typeof(XPathNodeIterator).Assembly; Type arrayIteratorType = systemXml.GetType("System.Xml.XPath.XPathArrayIterator"); return((XPathNodeIterator)Activator.CreateInstance(arrayIteratorType, BindingFlags.Instance | BindingFlags.Public | BindingFlags.CreateInstance, null, new object[] { list.innerList }, null)); }
}/* objecttype(object) */ /// <summary> /// This method converts an ExsltNodeList to an XPathNodeIterator over the nodes in the list. /// </summary> /// <param name="list">The list to convert</param> /// <returns>An XPathNodeIterator over the nodes in the original list</returns> /// <remarks>Known Issues: A node list containing multiple instances of an attribute /// with the same namespace name and local name will cause an error.</remarks> internal static XPathNodeIterator ExsltNodeListToXPathNodeIterator(ExsltNodeList list){ Assembly systemXml = typeof(XPathNodeIterator).Assembly; Type arrayIteratorType = systemXml.GetType("System.Xml.XPath.XPathArrayIterator"); return (XPathNodeIterator) Activator.CreateInstance( arrayIteratorType, BindingFlags.Instance | BindingFlags.Public | BindingFlags.CreateInstance, null, new object[]{ list.innerList}, null ); }
/// <summary> /// Implements the following function /// node-set distinct(node-set) /// </summary> /// <param name="nodeset">The input nodeset</param> /// <returns>Returns the nodes in the nodeset whose string value is /// distinct</returns> public static XPathNodeIterator distinct(XPathNodeIterator nodeset){ ExsltNodeList nodelist = new ExsltNodeList(); while(nodeset.MoveNext()){ if(!nodelist.ContainsValue(nodeset.Current.Value)){ nodelist.Add(nodeset.Current.Clone()); } } return ExsltCommon.ExsltNodeListToXPathNodeIterator(nodelist); }
/// <summary> /// Implements the following function /// node-set subset(node-set, node-set) /// </summary> /// <param name="nodeset1">An input nodeset</param> /// <param name="nodeset2">Another input nodeset</param> /// <returns>True if all the nodes in the first nodeset are contained /// in the second nodeset</returns> /// <remarks>THIS FUNCTION IS NOT PART OF EXSLT!!!</remarks> public static bool subset(XPathNodeIterator nodeset1, XPathNodeIterator nodeset2){ ExsltNodeList nodelist1 = new ExsltNodeList(nodeset1, true); ExsltNodeList nodelist2 = new ExsltNodeList(nodeset2, true); foreach(XPathNavigator nav in nodelist1){ if(!nodelist2.Contains(nav)){ return false; } } return true; }
/// <summary> /// Implements the following function /// node-set distinct(node-set) /// </summary> /// <param name="nodeset">The input nodeset</param> /// <returns>Returns the nodes in the nodeset whose string value is /// distinct</returns> public static XPathNodeIterator distinct(XPathNodeIterator nodeset) { ExsltNodeList nodelist = new ExsltNodeList(); while (nodeset.MoveNext()) { if (!nodelist.ContainsValue(nodeset.Current.Value)) { nodelist.Add(nodeset.Current.Clone()); } } return(ExsltCommon.ExsltNodeListToXPathNodeIterator(nodelist)); }
/// <summary> /// Implements /// boolean hassamenode(node-set, node-set) /// </summary> /// <param name="nodeset1"></param> /// <param name="nodeset2"></param> /// <returns>true if both nodeset contain at least one of the same node</returns> public static bool hassamenode(XPathNodeIterator nodeset1, XPathNodeIterator nodeset2) { ExsltNodeList nodelist1 = new ExsltNodeList(nodeset1, true); ExsltNodeList nodelist2 = new ExsltNodeList(nodeset2, true); foreach (XPathNavigator nav in nodelist1) { if (nodelist2.Contains(nav)) { return(true); } } return(false); }
/// <summary> /// Implements the following function /// node-set difference(node-set, node-set) /// </summary> /// <param name="nodeset1">An input nodeset</param> /// <param name="nodeset2">Another input nodeset</param> /// <returns>The those nodes that are in the node set /// passed as the first argument that are not in the node set /// passed as the second argument.</returns> public static XPathNodeIterator difference(XPathNodeIterator nodeset1, XPathNodeIterator nodeset2){ ExsltNodeList nodelist1 = new ExsltNodeList(nodeset1, true); ExsltNodeList nodelist2 = new ExsltNodeList(nodeset2); for(int i = 0; i < nodelist1.Count; i++){ XPathNavigator nav = nodelist1[i]; if(nodelist2.Contains(nav)){ nodelist1.RemoveAt(i); i--; } } return ExsltCommon.ExsltNodeListToXPathNodeIterator(nodelist1); }
/// <summary> /// Implements the following function /// node-set difference(node-set, node-set) /// </summary> /// <param name="nodeset1">An input nodeset</param> /// <param name="nodeset2">Another input nodeset</param> /// <returns>The those nodes that are in the node set /// passed as the first argument that are not in the node set /// passed as the second argument.</returns> public static XPathNodeIterator difference(XPathNodeIterator nodeset1, XPathNodeIterator nodeset2) { ExsltNodeList nodelist1 = new ExsltNodeList(nodeset1, true); ExsltNodeList nodelist2 = new ExsltNodeList(nodeset2); for (int i = 0; i < nodelist1.Count; i++) { XPathNavigator nav = nodelist1[i]; if (nodelist2.Contains(nav)) { nodelist1.RemoveAt(i); i--; } } return(ExsltCommon.ExsltNodeListToXPathNodeIterator(nodelist1)); }
/// <summary> /// Implements the following function /// node-set highest(node-set) /// </summary> /// <param name="iterator">The input nodeset</param> /// <returns>All the nodes that contain the max value in the nodeset</returns> public static XPathNodeIterator highest(XPathNodeIterator iterator) { ExsltNodeList newList = new ExsltNodeList(); double max, t; if (iterator.Count == 0) { return(ExsltCommon.ExsltNodeListToXPathNodeIterator(newList)); } try{ iterator.MoveNext(); max = XmlConvert.ToDouble(iterator.Current.Value); newList.Add(iterator.Current.Clone()); while (iterator.MoveNext()) { t = XmlConvert.ToDouble(iterator.Current.Value); if (t > max) { max = t; newList.Clear(); newList.Add(iterator.Current.Clone()); } else if (t == max) { newList.Add(iterator.Current.Clone()); } } }catch (Exception) { //return empty node set newList.Clear(); return(ExsltCommon.ExsltNodeListToXPathNodeIterator(newList)); } return(ExsltCommon.ExsltNodeListToXPathNodeIterator(newList)); }
/// <summary> /// Implements the following function /// node-set trailing(node-set, node-set) /// </summary> /// <param name="nodeset1"></param> /// <param name="nodeset2"></param> /// <returns>returns the nodes in the node set passed as the /// first argument that follow, in document order, the first node /// in the node set passed as the second argument</returns> public static XPathNodeIterator trailing(XPathNodeIterator nodeset1, XPathNodeIterator nodeset2){ XPathNavigator leader = null; if(nodeset2.MoveNext()){ leader = nodeset2.Current; }else{ return nodeset1; } ExsltNodeList nodelist1 = new ExsltNodeList(); while(nodeset1.MoveNext()){ if(nodeset1.Current.ComparePosition(leader) == XmlNodeOrder.After){ nodelist1.Add(nodeset1.Current.Clone()); } } return ExsltCommon.ExsltNodeListToXPathNodeIterator(nodelist1); }