Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 26th, 2012, 06:16 AM
Registered User
 
Join Date: Mar 2012
Posts: 6
Thanks: 3
Thanked 0 Times in 0 Posts
Default Count on multiple condition

Hi All,

I would like some help on counting the number of products in a particular category with a quantity greater than 0 using the following XML file

HTML Code:
<?xml version="1.0"?>
<Company xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <Products>
    <Product>
      <Id>5241</Id>
      <Sku>02854U</Sku>
      <Barcode />
      <Name>PDRAG</Name>
      <QtyInStock>1</QtyInStock>
      <Attributes>
        <Attribute>
          <Name>Current Stock</Name>
          <Value>Yes</Value>
        </Attribute>
	<Attribute>
          <Name>Amber Stock</Name>
          <Value>&lt;NONE&gt;</Value>
        </Attribute>
        <Attribute>
          <Name>Warehouse Name</Name>
          <Value>&lt;NONE&gt;</Value>
        </Attribute>
      </Attributes>
    </Product>
  </Products>
</Company>
I can count the number of products in the Current Stock category using this:
Code:
count(Company/Products/Product/Attributes/Attribute[Name='Current Stock' and Value='Yes'])
and also the number of products with a quantity greater than 0 using this:
Code:
count(Company/Products/Product[QtyInStock &gt; 0])
but how do i can combine the two??

thanks in advance

jonnyuk3
 
Old March 26th, 2012, 06:31 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

Your first condition would be better expressed as

Code:
count(Company/Products/Product[Attributes/Attribute[Name='Current Stock' and Value='Yes']])
the combined condition is then

Code:
count(Company/Products/Product[Attributes/Attribute[Name='Current Stock' and Value='Yes']][QtyInStock &gt; 0])
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference
The Following User Says Thank You to mhkay For This Useful Post:
jonnyuk3 (March 26th, 2012)
 
Old March 26th, 2012, 06:39 AM
Registered User
 
Join Date: Mar 2012
Posts: 6
Thanks: 3
Thanked 0 Times in 0 Posts
Default

Thanks mhkay, that works great.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Select Count from multiple tables aspless SQL Language 1 January 30th, 2008 10:32 AM
Count nodes based of if condition suri_1811 XSLT 1 December 7th, 2006 08:00 PM
is there any in built function to count page count g.tamilselvan MySQL 1 February 15th, 2006 07:43 AM
Count, sum, count a value, return records CongoGrey Access 1 April 18th, 2005 02:25 PM
count records where condition not true (IIF??) rpeksens Access 3 September 19th, 2003 03:36 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.