आप उपयोग कर सकते हैं preceding
और following
XPath कोई अधिक से अधिक मूल्य नहीं होता है कि क्या जांच करने के लिए अक्ष:
XmlDocument doc = new XmlDocument();
doc.LoadXml("<documents>"
+ " <document><id>3</id></document>"
+ " <document><id>7</id></document>"
+ " <document><id>1</id></document>"
+ "</documents>");
var max = doc.SelectSingleNode(
"/documents/document[not(id < preceding::document/id)
and not(id < following::document/id)]");
यदि कई अधिकतम आईडी मूल्यों दस्तावेज़ में उपरोक्त कोड पहले एक वापस आ जाएगी है। आप एक अधिकतम आईडी के साथ पिछले तत्व चाहते हैं तो आप
var max = doc.SelectSingleNode(
"/documents/document[not(id < preceding::document/id)
and not(id <= following::document/id)]");
उपयोग कर सकते हैं क्या आप SelectNodes
विधि का उपयोग कर सकते हैं एक अधिकतम आईडी होने के सभी तत्वों के साथ एक सूची प्राप्त करना चाहते हैं:
var maxList = doc.SelectNodes(
"/documents/document[not(id < preceding::document/id)
and not(id < following::document/id)]");
XSLT संस्करण :
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes"/>
<xsl:template match="/">
<root>
<xsl:value-of
select="/documents/document/id[not(. <= preceding::document/id)
and not(. <= following::document/id)]"/>
</root>
</xsl:template>
</xsl:stylesheet>
स्रोत
2010-09-24 11:24:46
+1 कम से कम और सही XPath 1.0 अधिकतम अभिव्यक्ति के लिए, cuadratic जटिलता के अलावा ... –
धन्यवाद, महान समाधान, आपको इसके लिए बोनस अंक प्राप्त करना चाहिए! – Hinek
चालाक समाधान! –