[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re[2]: Aggregate
Nagesh, > I would like to know if we can find out Maximum and Minumum of a element in > a xml file using xsl or any other XML technologes. The best way involves an XPath: the minimum value is the value of the node such that there are no other nodes that have a value less than that value; the maximum is the value of the node such that there are no other nodes with a value *more* than that value. So, to find the maximum of the 'in' elements, use: in[not(parent::TIME/in > .)] [in English: "the 'in' element(s) for which it is *not* the case that there is a 'in' element (child of the 'in' element's parent, 'TIME') that has a value less than the value of this one"] and to find the minimum: out[not(parent::TIME/out < .)] For some reason, I've also done this by sorting the elements, in either ascending or descending order, and picking out the first in the list. If you sort in ascending order, you'll get the minimum; if in descending order, the maximum. So, to find the maximum of the 'in' elements, use: <xsl:for-each select="in"> <xsl:sort select="." data-type="number" order="descending" /> <xsl:if test="position() = 1"> <xsl:value-of select="." /> </xsl:if> </xsl:for-each> I don't know why I've done it like this when the XPath is simpler and quicker - it probably just didn't occur to me at the time :) I hope that helps, Jeni --- Jeni Tennison http://www.jenitennison.com/ XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|