sum and preceding-sibling question

Discussion in 'XML' started by Chris, Apr 18, 2005.

  1. Chris

    Chris Guest

    I have the following XML structure:

    <NODE>
    <ITEM>
    <IMAGE>
    <FILE></FILE>
    <WIDTH></WIDTH>
    </IMAGE>
    </ITEM>
    <ITEM>
    <IMAGE>
    <FILE></FILE>
    <WIDTH></WIDTH>
    </IMAGE>
    </ITEM>
    <ITEM> --> current node
    <IMAGE>
    <FILE></FILE>
    <WIDTH></WIDTH>
    </IMAGE>
    </ITEM>
    </NODE>

    >From the ITEM node level I need to sum up all the image widths up to

    that point. I have playing around with preceding-sibling but can't seem
    to get the syntax right. I image it is something like this:

    <xsl:value-of select="sum(preceding-sibling::ONIMAGE/WIDTH)"/>

    Can someone help me? It would be greatly appreciated.

    Thanks!
     
    Chris, Apr 18, 2005
    #1
    1. Advertising

  2. Chris

    Soren Kuula Guest

    Hi,
    > <ITEM> --> current node
    > <IMAGE>
    > <FILE></FILE>
    > <WIDTH></WIDTH>
    > </IMAGE>
    > </ITEM>
    > </NODE>
    >
    >>From the ITEM node level I need to sum up all the image widths up to

    > that point. I have playing around with preceding-sibling but can't seem
    > to get the syntax right. I image it is something like this:
    >
    > <xsl:value-of select="sum(preceding-sibling::ONIMAGE/WIDTH)"/>
    >


    Looks fine with me, except that you have IMAGE elements, not ONIMAGE.

    Soren
     
    Soren Kuula, Apr 18, 2005
    #2
    1. Advertising

  3. >From the ITEM node level I need to sum up all the image widths up to
    >that point. I have playing around with preceding-sibling but can't seem
    >to get the syntax right. I image it is something like this:
    >
    ><xsl:value-of select="sum(preceding-sibling::ONIMAGE/WIDTH)"/>


    Judging by your posted sample the siblings of ITEM are all called ITEM
    and there are no elements called ONIMAGE

    so I guess that should be

    <xsl:value-of select="sum(preceding-sibling::ITEM/IMAGE/WIDTH)"/>

    David
     
    David Carlisle, Apr 18, 2005
    #3
  4. Chris

    Chris Guest

    Hi,

    Thanks again for the replies!

    Sorry, I should have written:

    <xsl:value-of select="sum(preceding-sibling:­:IMAGE/WIDTH)"/>

    but for some reason

    <xsl:value-of select="sum(preceding-sibling:­:ITEM/IMAGE/WIDTH)"/>

    is still returning 0. Should I include ITEM in that xpath even though
    I'm in the ITEM node?
     
    Chris, Apr 18, 2005
    #4
  5. Sorry, I should have written:

    <xsl:value-of select="sum(preceding-sibling::IMAGE/WIDTH)"/>

    That won't work as the IMAGE elements are not siblings.


    <xsl:value-of select="sum(preceding-sibling::ITEM/IMAGE/WIDTH)"/>

    is still returning 0. Should I include ITEM in that xpath even though
    I'm in the ITEM node?

    That will work if
    a) your source looked like you said it looked (but with values in the WIDTH), and
    b) your current node was teh ITEM node that you thought it was.

    usually it's (b) that catches people out, are you sure that you are
    where you think you are?

    David
     
    David Carlisle, Apr 18, 2005
    #5
  6. Chris

    Chris Guest

    I got it. Works prefectly. Thanks so much David!
     
    Chris, Apr 19, 2005
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. TadPole
    Replies:
    0
    Views:
    437
    TadPole
    Nov 8, 2005
  2. Replies:
    11
    Views:
    662
    Fredrik Lundh
    Jan 23, 2006
  3. johkar
    Replies:
    4
    Views:
    769
    johkar
    Oct 21, 2006
  4. Matt Waite
    Replies:
    4
    Views:
    359
    Matt Waite
    Feb 1, 2007
  5. Red
    Replies:
    2
    Views:
    1,230
    Pavel Lepin
    May 9, 2007
Loading...

Share This Page