Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Matias Korn 30 posts 49 karma points
    Aug 20, 2012 @ 19:12
    Matias Korn
    0

    add a value to a container/variable

    Hello.

    i need to get the total number from several documents.

    Lets imagine i have like 4 documents and each of these container a property called AmountJobs.

    First doc, AmountJobs: 2.
    Second doc, AmountJobs: 1
    Third doc, AmountJobs: 4
    Fourth doc, AmountJobs: 1

    The total number of AmountJobs from all documents is: 8.

    How can i get that number?

    <xsl:variable name="amountJobs" select="0" />
      <xsl:for-each select="*">
    <xsl:variable name="amountJobs" select="$amountJobs + number(AmountJobs)" />
      </xsl:for-each>   

    <xsl:value-of select="$amountJobs" /> 

    This is the code i have, but i cant do that. I cant use a variable.

  • Chriztian Steinmeier 2800 posts 8791 karma points MVP 8x admin c-trib
    Aug 20, 2012 @ 19:53
    Chriztian Steinmeier
    0

    Hi Mathias,

    You use the sum() function for that, e.g. to get the amount of jobs for the current page and its siblings:

    <xsl:value-of select="sum($currentPage/../*[@isDoc]/AmountJobs)" />

     

    /Chriztian

  • Ernst Utvik 123 posts 235 karma points
    Aug 20, 2012 @ 19:57
    Ernst Utvik
    0

    It really should be that easy, but unfortunately it isn't. 

    In xslt you can't change a variable once it is declared. I did something similar to what you are describing above a couple of years ago by calling a template with a parameter but I can't find the code.

    Is using Razor an option?

  • Ernst Utvik 123 posts 235 karma points
    Aug 20, 2012 @ 19:59
    Ernst Utvik
    0

    Or just do it the way Chriztian describes ;) 

  • Matias Korn 30 posts 49 karma points
    Aug 20, 2012 @ 20:06
    Matias Korn
    0

    Thanks Chriztian, nice one and it worked perfectly

Please Sign in or register to post replies

Write your reply to:

Draft