473,395 Members | 1,956 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,395 software developers and data experts.

sum values by lookup

Dear Experts,

right on time before Xmas I have something to think about.
I want to sum up values by using a key. But the value which is used as
a selctor in the key function is a node-set.

I made a smal test program and run it with 3 pocessors.
ALTOVA (XMLSPY 2005) , MSXML4 , SAXON 8.

The results and messages differ !
ALTOVA( = 1300 (which was my expectation)
MSXML4 = 600 (which is may be right, but not was was expecting)
SAXON8 = 600 ( with additional warning )

1) What is correct way to make my dream come true ?
2) Why does SAXON complain (I'm using XSLT version 1.0 )

Plaese find below a test case

Thanks for your inputs and marry Christmas
Rolf

################# xml data ##################################
<?xml version="1.0" encoding="UTF-8"?>
<SumTest>
<Cells>
<Cell Name="A" Size="100"/>
<Cell Name="B" Size="200"/>
<Cell Name="C" Size="300"/>
</Cells>
<Instancies>
<Instance InstName="I1" CellName="A" Index="1" /><!-- 100 -->
<Instance InstName="I2" CellName="B" Index="2" /><!-- 200 -->
<Instance InstName="I3" CellName="A" Index="3" /><!-- 100 -->
<Instance InstName="I4" CellName="A" Index="4" /><!-- 100 -->
<Instance InstName="I5" CellName="C" Index="5" /><!-- 300 -->
<Instance InstName="I6" CellName="C" Index="6" /><!-- 300 -->
<Instance InstName="I7" CellName="B" Index="7" /><!-- 200 -->
<Instance InstName="I8" CellName="B" Index="8" /><!-- unselected-->
<Instance InstName="I9" CellName="C" Index="9" /><!-- unselected-->
</Instancies>
<!-- 3*A = 300 + 2*B = 400 + 2*C = 600 should sum up to 1300 -->
<!-- altova = 1300 (which might be OK just by different
interpretation of key/sum ) -->
<!-- msxml4 = 600 ( which is A+B+C probably first occurence of node
is used as key valu probably ) -->
<!-- saxon8 = 600 ( which is A+B+C probably first occurence of
node is used as key valu probably )
WARNING on compare !! comparsion of a node-set to a boolean has
changed dsince XPATH 1.0 "
-->
</SumTest>
################## xslt #######################################
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text" version="1.0" encoding="UTF-8"/>
<xsl:key name="kCells" match="/SumTest/Cells/Cell" use="@Name"/>
<xsl:variable name="gEndIndex"
select="/SumTest/Instancies/Instance[@InstName='I8']/@Index"/>
<xsl:variable name="gInstancies"
select="/SumTest/Instancies/Instance[@Index &gt; 0 and @Index &lt;
$gEndIndex ]"/>
<xsl:variable name="vSumSize" select="sum(
key('kCells',$gInstancies/@CellName)/@Size)"/>
<xsl:template match="/">
<xsl:text>selected node count =</xsl:text>
<xsl:value-of select="count($gInstancies)"/>
<xsl:text>
</xsl:text>
<xsl:text>SumSize=</xsl:text>
<xsl:value-of select="$vSumSize"/>
<xsl:text>
</xsl:text>
</xsl:template>
</xsl:stylesheet>

######################## END ############################
Jul 20 '05 #1
2 1665
Rolf Kemper wrote:
<xsl:key name="kCells" match="/SumTest/Cells/Cell" use="@Name"/>
<xsl:variable name="gEndIndex"
select="/SumTest/Instancies/Instance[@InstName='I8']/@Index"/>
<xsl:variable name="gInstancies"
select="/SumTest/Instancies/Instance[@Index &gt; 0 and @Index &lt;
$gEndIndex ]"/>
<xsl:variable name="gNames" select="$gInstancies/@CellName" />
<xsl:variable name="gCells" select="key('kCells', $gNames)" />
<xsl:variable name="gSizes" select="$gCells/@Size" />
<xsl:variable name="vSumSize" select="sum(
key('kCells',$gInstancies/@CellName)/@Size)"/>


Rolf, I am using ASP.NET 2.0 (not sure which MSXML parser it is). Your
key lookup is only returning unique instances of the Cell element. If
you split up your complex lookup as I have done above, and then output
the count of $gCells and play with your data file, and your $gInstances
boundary, you will see this behavior.

In the case you have set up, all three Cells appear as Instancies, so
you get all three (and only all three) as $gCells. If you construct a
situation where only "A" and "B" appear as Instancies, no matter how
many times they appear, your $gCells will only have the two, and your
sum will be 300.

I'm not sure how to make your functionality work, but this is why it isn't.

Luke
Jul 20 '05 #2
Luke Dalessandro wrote:
Rolf, I am using ASP.NET 2.0 (not sure which MSXML parser it is). Your
key lookup is only returning unique instances of the Cell element.


To clarify my point, according to the standard near
http://www.w3.org/TR/1999/REC-xslt-19991116#key, in the definition of
the function "key":

"When the second argument to the key function is of type node-set, then
the result is the union of the result of applying the key function to
the string value of each of the nodes in the argument node-set."

The union is not an accumulation. Each unique node found will only
appear once.

Luke
Jul 20 '05 #3

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

Similar topics

1
by: James E | last post by:
I have a question about best practices of how to deal with lookup data from my C# apps. On a couple of occasions I have come across a problem where I have to automate inserting a record into a...
1
by: Sophie Bradshaw | last post by:
i was wondering if anyone could possibly help me! i have a ms access database, and in one of the tables, one of the fields is a lookup column, with several possible values. what i want to do is...
3
by: Tripp Knightly | last post by:
I have a lookup table from which I want to categorize various bands of customer net income. Some of the income is positive, some is negative. The bands vary in size (ie, <500, -200 to 0, 100 to...
4
by: Vik | last post by:
How can I display the lookup values in a datagrid? E.g., the datagrid displays a table that contains a ProductID field. I want to display a Product description from a Product table in that...
0
by: dbuchanan | last post by:
Hello, For my datagrid I added a datagrid table style to include columns from my lookup tables. These display the values in the lookup tables rather than just the integer key value stored in the...
3
by: dbuchanan | last post by:
Hello, (Windows forms - SQL Server) I fill my datagrid with a stored procedure that includes relationships to lookup tables so that users can see the values of the combobox selections rather...
14
by: John Welch | last post by:
Hi all. I'm creating a FE/BE database that will be used by about 6 users. As usual, I have several fields, such as "OrganizationTypeID" that will get values (via combo boxes in forms) from separate...
0
by: TB | last post by:
Hi there, To make data capturing a bit easier for myself, on one of the fields i decided to use a lookup value list to insert some common values in a certain field of a record. My database...
2
by: axapta | last post by:
I'm returning values in my form from a table. However some of these values are based on lookups stored in another table. How can I retrieve the description of the values from the lookup table...
14
by: Mark | last post by:
I have a table with a field that uses a combobox to populate values. The Lookup tab within table design mode is the following: Display Control Combo Box Row Source Type ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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
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...

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.