473,761 Members | 9,284 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Selecting Nodes Using Subtotal of Child Nodes

I'm having difficulty finding the correct syntax that will allow me to
select a group of invoices based on the total of an amount column
located in its line items. Below are simplified examples of my XML and
XSLT files:

XML FILE

<?xml version="1.0" standalone="yes "?>
<?xml-stylesheet type="text/xsl"
href="Outstandi ngInvoiceBalanc es.xslt"?>
<ProgramData>
<Invoices>
<InvoiceID>1</InvoiceID>
<InvoiceNumber> 100</InvoiceNumber>
<Amount>1000.00 </Amount>
</Invoices>
<Invoices>
<InvoiceID>2</InvoiceID>
<InvoiceNumber> 101</InvoiceNumber>
<Amount>2000.00 </Amount>
</Invoices>
<Invoices>
<InvoiceID>3</InvoiceID>
<InvoiceNumber> 102</InvoiceNumber>
<Amount>3000.00 </Amount>
</Invoices>
<InvoiceLineIte ms>
<InvoiceLineIte mID>1</InvoiceLineItem ID>
<InvoiceID>1</InvoiceID>
<AmountToPay> 0</AmountToPay>
</InvoiceLineItem s>
<InvoiceLineIte ms>
<InvoiceLineIte mID>2</InvoiceLineItem ID>
<InvoiceID>2</InvoiceID>
<AmountToPay>10 0</AmountToPay>
</InvoiceLineItem s>
<InvoiceLineIte ms>
<InvoiceLineIte mID>3</InvoiceLineItem ID>
<InvoiceID>2</InvoiceID>
<AmountToPay>20 0</AmountToPay>
</InvoiceLineItem s>
<InvoiceLineIte ms>
<InvoiceLineIte mID>4</InvoiceLineItem ID>
<InvoiceID>3</InvoiceID>
<AmountToPay>10 0</AmountToPay>
</InvoiceLineItem s>
<InvoiceLineIte ms>
<InvoiceLineIte mID>5</InvoiceLineItem ID>
<InvoiceID>3</InvoiceID>
<AmountToPay>20 0</AmountToPay>
</InvoiceLineItem s>
<InvoiceLineIte ms>
<InvoiceLineIte mID>6</InvoiceLineItem ID>
<InvoiceID>3</InvoiceID>
<AmountToPay>30 0</AmountToPay>
</InvoiceLineItem s>
</ProgramData>
XSLT FILE

<?xml version="1.0"?>
<xsl:styleshe et version="1.0"
xmlns:xsl="http ://www.w3.org/1999/XSL/Transform"
xmlns="http://www.w3.org/TR/REC-html40"
xmlns:msxsl="ur n:schemas-microsoft-com:xslt"
xmlns:local="#l ocal-functions">
<xsl:template match="/">
<HTML>
<BODY>
<TABLE CELLSPACING="1" CELLPADDING="1" BORDER="0">
<TR>
<TH>Invoice Number</TH>
<TH width="10"></TH>
<TH align="right">A mount</TH>
<TH width="10"></TH>
<TH align="right">A mount Paid</TH>
</TR>
<TR>
<TD colspan="17" height="1" bgcolor="black" ></TD>
</TR>

<xsl:variable name="SelectDat a" select="Program Data/Invoices"
/>
<xsl:for-each select="$Select Data">

<xsl:variable name="AmountToP ay"
select="sum(//InvoiceLineItem s[InvoiceID=curre nt()/InvoiceID]/AmountToPay)"
/>
<TR>
<TD><xsl:valu e-of select="Invoice Number" /></TD>
<TD></TD>
<TD align="right">< xsl:value-of
select="format-number(Amount, '#,##0.00')" /></TD>
<TD></TD>
<TD align="right">< xsl:value-of
select="format-number($AmountT oPay, '#,##0.00')" /></TD>
</TR>

</xsl:for-each>

<TR>
<TD colspan="17" height="1" bgcolor="black" ></TD>
</TR>
<xsl:variable name="GrandAmou nt"
select="sum($Se lectData/Amount)" />
<xsl:variable name="GrandAmou ntToPay"
select="sum(Pro gramData/InvoiceLineItem s[InvoiceID=$Sele ctData/InvoiceID]/AmountToPay)"
/>
<TR>
<TD>Grand Total</TD>
<TD></TD>
<TD align="right">< xsl:value-of
select="format-number($GrandAm ount, '#,##0.00')" /></TD>
<TD></TD>
<TD align="right">< xsl:value-of
select="format-number($GrandAm ountToPay, '#,##0.00')" /></TD>
</TR>

</TABLE>
</BODY>
</HTML>
</xsl:template>
</xsl:stylesheet>
When I run the translation I get the following result:

Invoice Number Amount Amount Paid
100 1,000.00 0.00
101 2,000.00 300.00
102 3,000.00 600.00
Grand Total 6,000.00 900.00

As you can see from the script each invoice's Amount Paid value is
calculated as the sum of its line item Amount Paid values. What I
would like to do is only display those invoices where the Amount Paid
is greater than 0. I realize I could wrap the code contained within
the for-each loop with a test to ensure the the sum is greater than 0
before writing the value but that doesn't help the Grand Total row. It
would still include all invoices in its summation. Using the example
above, the Grand Total of the Amount column would still be 6,000.00
despite the fact that invoice 100 would not be displayed.

What I've tried to do is exclude those invoices from the $SelectData
variable. If I can do that the entire sheet would calculate correctly:

Invoice Number Amount Amount Paid
101 2,000.00 300.00
102 3,000.00 600.00
Grand Total 5,000.00 900.00

I've tried everything I can think of to accomplish this to no avail.
If anyone can point me in the right direction I would appreciate it.

Thanks

Aug 23 '06 #1
1 1824
re*********@hot mail.com wrote:
I'm having difficulty finding the correct syntax that will allow me to
select a group of invoices based on the total of an amount column
located in its line items. Below are simplified examples of my XML and
XSLT files:
.....
When I run the translation I get the following result:

Invoice Number Amount Amount Paid
100 1,000.00 0.00
101 2,000.00 300.00
102 3,000.00 600.00
Grand Total 6,000.00 900.00

As you can see from the script each invoice's Amount Paid value is
calculated as the sum of its line item Amount Paid values. What I
would like to do is only display those invoices where the Amount Paid
is greater than 0.
Wait -- I am confused about the things that are named AmountToPay, that
you call amount paid??? As far as I know, that something is to pay means
is not yet paid?
I realize I could wrap the code contained within
the for-each loop with a test to ensure the the sum is greater than 0
before writing the value but that doesn't help the Grand Total row. It
would still include all invoices in its summation. Using the example
above, the Grand Total of the Amount column would still be 6,000.00
despite the fact that invoice 100 would not be displayed.

What I've tried to do is exclude those invoices from the $SelectData
variable. If I can do that the entire sheet would calculate correctly:

Invoice Number Amount Amount Paid
101 2,000.00 300.00
102 3,000.00 600.00
Grand Total 5,000.00 900.00

I've tried everything I can think of to accomplish this to no avail.
If anyone can point me in the right direction I would appreciate it.
Try a key: The 'gedefims' one I included rounds up a map from each
InvoiceID to lists of InvoiceLineItem s with the ID. That is then used
later in a predicate, where the text value of the InvoiceID children are
used for looking up the lists. The list nodes' AmountToPay children are
summed, and if the result 0, the Amount child of the parent of
InvoiceID's parent is included in the grand total.......... .

<?xml version="1.0"?>
<xsl:styleshe et xmlns:xsl="http ://www.w3.org/1999/XSL/Transform"
xmlns="http://www.w3.org/TR/REC-html40"
xmlns:msxsl="ur n:schemas-microsoft-com:xslt"
xmlns:local="#l ocal-functions" version="1.0">
<xsl:key name="gedefims" match="InvoiceL ineItems" use="InvoiceID"/>
<xsl:template match="/">
<HTML>
<BODY>
<TABLE CELLSPACING="1" CELLPADDING="1" BORDER="0">
<TR>
<TH>Invoice Number</TH>
<TH width="10"/>
<TH align="right">A mount</TH>
<TH width="10"/>
<TH align="right">A mount Paid</TH>
</TR>
<TR>
<TD colspan="17" height="1" bgcolor="black"/>
</TR>
<xsl:variable name="SelectDat a" select="Program Data/Invoices"/>
<xsl:for-each select="$Select Data">
<xsl:variable name="AmountToP ay"
select="sum(//InvoiceLineItem s[InvoiceID=curre nt()/InvoiceID]/AmountToPay)"/>
<xsl:if test="$AmountTo Pay &gt; 0">
<TR>
<TD>
<xsl:value-of select="Invoice Number"/>
</TD>
<TD/>
<TD align="right">
<xsl:value-of select="format-number(Amount,
'#,##0.00')"/>
</TD>
<TD/>
<TD align="right">
<xsl:value-of select="format-number($AmountT oPay,
'#,##0.00')"/>
</TD>
</TR>
</xsl:if>
</xsl:for-each>
<TR>
<TD colspan="17" height="1" bgcolor="black"/>
</TR>
<xsl:variable name="GrandAmou nt"
select="sum(/ProgramData/Invoices [sum(key('gedefi ms',
InvoiceID)/AmountToPay) &gt; 0]/Amount)"/>
<xsl:variable name="GrandAmou ntToPay"
select="sum(Pro gramData/InvoiceLineItem s[InvoiceID=$Sele ctData/InvoiceID]/AmountToPay)"/>
<TR>
<TD>Grand Total</TD>
<TD/>
<TD align="right">
<xsl:value-of select="format-number($GrandAm ount,
'#,##0.00')"/>
</TD>
<TD/>
<TD align="right">
<xsl:value-of select="format-number($GrandAm ountToPay,
'#,##0.00')"/>
</TD>
</TR>
</TABLE>
</BODY>
</HTML>
</xsl:template>
</xsl:stylesheet>

Hope that confused --- uh, helped,

Søren
Aug 24 '06 #2

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

Similar topics

3
1742
by: Jamie Green | last post by:
Using MSXML3.0, with the Dom SelectionLanguage set to Xpath I am trying to query the following document <Root> <Child>Name</Child> <Child>John</Child> <Child>Smith</Child> <Child>23</Child> <Child>Name</Child> <Child>Peter</Child>
0
1381
by: J. T. | last post by:
I'm fairly new to XSL, but have made some good progress in picking it up for the project I'm currently working on. I've been trying to figure out how to design a stylesheet that would transform the XML I'm recieving so that the tax information I'm recieving per item could be grouped and added per state and have the new subtotal node located inside the last node of a particular STORE value. I'm trying to use the Muenchian Method, but I...
9
16673
by: Tjerk Wolterink | last post by:
Hello, suppose i have a dom like this: <a> - <b> - <b> - <d> - </b> - <c>
2
10701
by: Greg | last post by:
Hi. I have a rather large xml document (object) that can have one or more nodes with a certain attribute throughout (at ANY depth, not at the same level necessarily). I need to find this attribute and remove the containing node (and child nodes) if it has a certain value. I'm able to find the attributes using an XmlTextReader. Once found, can someone help me get the XPath at that point? I would then use this to remove the node from...
1
1589
by: Nancy Shelley | last post by:
Hi all: I am building a navigation menu using telerik's rad treeview I am able to build the outer menu but not the children. How do I select the child nodes (item) from within the loop? Any help would be greatly appreciated!! Dim node As XmlNode For Each node In xmlDoc.SelectNodes("/configuration/groups/group/menus/menu")
2
1490
by: Saurabh Sharma | last post by:
Hi, I am using Dom Parsing in Xml. I am the parent node and it has many children and each children has many children. I want to select children with a given name . Is there any method by which we select them with not going to each child node .. something like node.selectnodes (* + "/ABC"); I have time constraint and also i have to do changes so have to use DOM
2
1362
by: Marc Jennings | last post by:
Hi there, I have been given a rather poor schema for an XML file in the following format : ><item> > <key>ProductCode</key> > <value>1234-5678</value> > <key>Description</key> > <value>Widget 1</value>
2
7499
by: Tymbow | last post by:
I'm building a web application that is analogous to the Windows XP file explorer in function. The left column contains a TreeView, and the right column a DataGrid populated by selecting TreeView nodes. The TreeView populates dynamically as there are a significant number of nodes. The DataGrid displays both the items and the nodes from the TreeView. Using the explorer analogy this means the TreeView shows folders, and the DataGrid folders...
1
1550
by: jdhcards | last post by:
Hello, I've been banging my head against a problem all day without a solution, and I'm hoping you all can help. I've got a piece of XML that defines a set of elements in a flat list. Each of these elements has an attribute "Id" which has a unique value. Some of these elements have a parent-child relationship, specified with a "ResultId" attribute in one of the child nodes. <element id=1>
0
9554
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9376
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10136
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9923
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9811
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6640
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5266
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5405
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3911
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.