Re: [xsl] sum of duration as string

Subject: Re: [xsl] sum of duration as string
From: "Christophe Marchand cmarchand@xxxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Wed, 9 Mar 2016 16:42:07 -0000
Thanks to all of you !
And I must go and learn actively XPath 3.1 !

Best,
Christophe

Le 09/03/2016 16:37, Michael Kay mike@xxxxxxxxxxxx a C)crit :
> And just for good measure, in XPath 3.1 idiom you can write
>
> <sum>{(. => tokenize(',')) [ position() mod 2 = 1 ] ! 
> xs:dayTimeDuration(.) => sum()}</sum>
>
> Michael Kay
> Saxonica
>
>
>> On 9 Mar 2016, at 15:26, Dr. Patrik Stellmann 
>> patrik.stellmann@xxxxxxxxx <mailto:patrik.stellmann@xxxxxxxxx> 
>> <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx 
>> <mailto:xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>> wrote:
>>
>> Something like this should work:
>>
>> <xsl:value-ofselect="sum(for $i in tokenize(., ',')[(position() mod 
>> 2) = 1] return xs:dayTimeDuration($i))"/>
>>
>> Regards,
>>
>> Patrik
>>
>>
>> ------------------------------------------------------------------
>> Systemarchitektur & IT-Projekte
>> Tel: +49 40 33449-1142
>> Fax: +49 40 33449-1400
>> E-Mail: Patrik.Stellmann@xxxxxxxxx <mailto:Patrik.Stellmann@xxxxxxxxx>
>>
>>
>> *Von:*cmarchand@xxxxxxxxxx <mailto:cmarchand@xxxxxxxxxx> 
>> [mailto:xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx]
>> *Gesendet:* Mittwoch, 9. MC$rz 2016 15:42
>> *An:* xsl-list@xxxxxxxxxxxxxxxxxxxxxx 
>> <mailto:xsl-list@xxxxxxxxxxxxxxxxxxxxxx>
>> *Betreff:* [xsl] sum of duration as string
>>
>> Hello,
>>
>> I have a comma separated string of durations :
>>
>> <base 
>> name='BASECOCOS'>PT2.206S,PT2.206S,PT0.435S,PT0.435S,PT1.022S,PT1.022S,PT1.490S,PT1.490S,PT12M15.963S,PT12M15.963S</base>
>>
>> I want to calculate the sum of the durations who are in odd positions.
>>
>> I've tried this :
>>
>> <xsl:function name="local:sumDuration" as="xs:duration">
>>    <xsl:param name="seq" as="xs:string+"/>
>>    <xsl:choose>
>>       <xsl:when test="count($seq) ge 3">
>>          <xsl:variable name="dur1" as="xs:duration" 
>> select="xs:duration($seq[1])"/>
>>          <xsl:value-of select="$dur1 + 
>> local:sumDuration(subsequence($seq,3))"/>
>>       </xsl:when>
>>       <xsl:otherwise>
>>          <xsl:value-of select="xs:duration($seq[1])"/>
>>       </xsl:otherwise>
>>    </xsl:choose>
>> </xsl:function>
>>
>> ...
>>
>>  <xsl:value-of select="local:sumDuration(tokenize(./text(),','))"/>
>>
>> I get this error :
>>
>> ID SystC(me: 
>> /home/ext-cmarchand/devel/avo-optim/inneo/src/main/makeTempsTableFromLogs/xslt/makeTable.xsl
>> ScC)nario: makeTable
>> fichier XSL: 
>> /home/ext-cmarchand/devel/avo-optim/inneo/src/main/makeTempsTableFromLogs/xslt/makeTable.xsl
>> Nom du moteur: Saxon-PE 9.5.1.3
>> GravitC): fatal
>> Description: XPTY0004: Only subtypes of xs:duration can be added
>> Emplacement de dC)but: 245:0
>> URL: http://www.w3.org/TR/xpath20/#ERRXPTY0004
>>
>> I use /xsl:stylesheet/@version="2.0" with Saxon-PE 9.5.1.3
>>
>> Any help will be much appreciated.
>>
>> Christophe
>>
>> XSL-List info and archive <http://www.mulberrytech.com/xsl/xsl-list>
>>
>> EasyUnsubscribe <x-msg://37/-list/2718916> (by email)
>>
>>
>> *GDV Dienstleistungs-GmbH & Co. KG*
>> GlockengieCerwall 1
>> D-20095 Hamburg
>> www.gdv-dl.de <http://www.gdv-dl.de>
>>
>> Sitz und Registergericht: Hamburg
>> HRA 93 894
>> USt.-IdNr : DE 205183123
>>
>> KomplementC$rin:
>> GDV Beteiligungsgesellschaft mbH
>> Sitz und Registergericht: Hamburg
>> HRB 71 153
>>
>> GeschC$ftsfC<hrer:
>> Dr. Jens Bartenwerfer
>> Michael Bathke
>> Volker Sonnenburg
>>
>> ------------------------------------------------------------------
>> Diese E-Mail und alle AnhC$nge enthalten vertrauliche und/oder 
>> rechtlich geschC<tzte Informationen. Wenn Sie nicht der richtige 
>> Adressat sind oder diese E-Mail irrtC<mlich erhalten haben, 
>> informieren Sie bitte sofort den Absender und vernichten Sie diese 
>> E-Mail. Das unerlaubte Kopieren sowie die unbefugte Weitergabe der 
>> E-Mail ist nicht gestattet.
>>
>> This e-mail and any attached files may contain confidential and/or 
>> privileged information. If you are not the intended recipient (or 
>> have received this e-mail in error) please notify the sender 
>> immediately and destroy this e-mail. Any unauthorised copying, 
>> disclosure or distribution of the material in this e-mail is strictly 
>> forbidden.
>>
>> XSL-List info and archive <http://www.mulberrytech.com/xsl/xsl-list>
>> EasyUnsubscribe <-list/293509> (by email)
>
> XSL-List info and archive <http://www.mulberrytech.com/xsl/xsl-list>
> EasyUnsubscribe <-list/2837134> 
> (by email <>)

Current Thread