sum and preceding-sibling question

C

Chris

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>
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!
 
S

Soren Kuula

Hi,
<ITEM> --> current node
<IMAGE>
<FILE></FILE>
<WIDTH></WIDTH>
</IMAGE>
</ITEM>

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
 
D

David Carlisle

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
 
C

Chris

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?
 
D

David Carlisle

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top