Subject: Re: [xsl] sum of duration as string From: "Michael Kay mike@xxxxxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> Date: Wed, 9 Mar 2016 15:37:33 -0000 |
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 <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> wrote: > > Something like this should work: > > <xsl:value-of select="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:xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx] > Gesendet: Mittwoch, 9. MC$rz 2016 15:42 > An: 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.49 0S,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/xsl t/makeTable.xsl > ScC)nario: makeTable > fichier XSL: /home/ext-cmarchand/devel/avo-optim/inneo/src/main/makeTempsTableFromLogs/xsl t/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 <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 <applewebdata://881C18B5-FC23-4812-905E-D29FBFBE83C9>) > > GDV Dienstleistungs-GmbH & Co. KG > GlockengieCerwall 1 > D-20095 Hamburg > 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 <>)
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
AW: [xsl] sum of duration as string, Dr. Patrik Stellmann | Thread | Re: [xsl] sum of duration as string, Christophe Marchand |
AW: [xsl] sum of duration as string, Dr. Patrik Stellmann | Date | Re: [xsl] sum of duration as string, Christophe Marchand |
Month |