473,396 Members | 2,011 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

sum and preceding-sibling question

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!

Jul 20 '05 #1
5 1901
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

Jul 20 '05 #2
>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
Jul 20 '05 #3
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?

Jul 20 '05 #4

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
Jul 20 '05 #5
I got it. Works prefectly. Thanks so much David!

Jul 20 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Jeb Hunter | last post by:
Seems to be arbitrarily specified or omitted in various documents. Maybe this is a PHP element that I've not encountered yet, being new to it. Or is there some XSLT-specific reason for this? ...
6
by: JT | last post by:
how would i transform this number: 00000102 into 102 basically, i just want to remove all preceding zeroes, but not replace all zeroes
2
by: Sven | last post by:
Hi I have the following XML & XSLT: XML: <?xml version="1.0" encoding="utf-8"?> <Source Source="IBM"> <Detail> <UserID></UserID>
2
by: KJ | last post by:
Hello All, I'd like to know what the difference is between these 2 expressions: parent::*/preceding-sib­ling::tagname VS parent::preceding-sib­ling::tagname
6
by: John | last post by:
Hi I would like to convert a number to string but with a preceding zero if the number is less than 10. How can I accomplish this? Thanks Regards
2
by: Greg Collins [Microsoft MVP] | last post by:
In reviewing my web site statistics, I see that I get 404 errors (often enough to make me ask about it) when users try to click on a link to a secure external site (i.e. an https:// link). I've...
1
by: max | last post by:
I have a field containing total sales. What I would like to do is create a new field that would show the difference in sales from either the preceding or next record. I know this could be...
2
by: saengpole | last post by:
Hi all, I'm a newbie in VB2005. I have a trouble getting text from textbox and combobox.SelectedValue. The values reside on two controls are text. But they are in numeric text eg. product code...
1
by: rnakawat | last post by:
I seem to have a problem using the preceding:: on substrings of the value. I'll try to explain with an example: Let's say I had a XML that look like: <Root> <Row> <Cell Name="Street"...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.