xsl-list
[Top] [All Lists]

RE: Summing Time Durations Help

2005-10-05 01:35:59

    Kent> I have some duration elements like <alltimes>
    Kent> <tduration>PT1H23M</tduration> <tduration>PT5M</tduration>
    Kent> <tduration>PT44M12S</tduration>
    Kent> <tduration>PT57M23S</tduration> ...  </alltimes>

    Kent> What is the most efficient way to sum the durations?  Is
    Kent> there an xpath = expression for this?

Yes. If you are using XPath 2.0.
You should use the sum() function.
But first you need some duration values - at present, all you have are
string literals - untyped text nodes.

Colin, you're right, on the assumption that there's no schema and that the
transformation isn't schema-aware. If there's a schema that describes these
elements as being of type xdt:dayTimeDuration, and if you use a schema-aware
processor, then you can just sum them directly: sum(tduration).

Michael Kay
http://www.saxonica.com/



--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--



<Prev in Thread] Current Thread [Next in Thread>