?
Solved

XSLT count with double criteria

Posted on 2009-04-27
2
Medium Priority
?
368 Views
Last Modified: 2013-11-18
Hello Experts,

I need some help with XSLT and COUNT function. The XML looks like this (it is just a sample similar to actual XML which is quite complex):

<nodes>
      <node>
            <data alias="subitemCategory">Category 1</data>
      </node>
      <node>
            <data alias="subitemCategory">Category 1</data>
      </node>
      <node>
            <data alias="subitemCategory">Category 2</data>
      </node>
      <categories>
            <node>
                  <data alias="category">Category 1</data>
            </node>
            <node>
                  <data alias="category">Category 2</data>
            </node>
      </categories>
</nodes>

I need to write an XSLT to count nodes with alias=subitemCategory and with data equal to "Category 1".

I wrote something like:
<xsl:value-of select="count(nodes/node/data [@alias = 'subitemCategory'])"/>

and I can write something like:
<xsl:value-of select="count(nodes/node[data  = 'Category 1'])"/>

but I don't know how to write a single "count" function and to specify both criteria:
 - @alias = 'subitemCategory'
 - data = 'Category 1'.

I would appriciate any kind of help.
0
Comment
Question by:sasapopovic
2 Comments
 
LVL 19

Accepted Solution

by:
zc2 earned 2000 total points
ID: 24245868
You said nothing about the nodes inside the "categories" element. Should the be count?
If not use the first expression of the following, if yes - the second one
<xsl:value-of select="count(nodes/node[data/@alias = 'subitemCategory' and data = 'Category 1'])"/>
<xsl:value-of select="count(nodes//node[data/@alias = 'subitemCategory' and data = 'Category 1'])"/>

Open in new window

0
 
LVL 9

Author Closing Comment

by:sasapopovic
ID: 31575185
Hello zc2,

The first one was what I needed. Thank you very much!

Regards,
Sasa
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Preface In the first article: A Better Website Login System (http://www.experts-exchange.com/A_2902.html) I introduced the EE Collaborative Login System and its intended purpose. In this article I will discuss some of the design consideratio…
What is Node.js? Node.js is a server side scripting language much like PHP or ASP but is used to implement the complete package of HTTP webserver and application framework. The difference is that Node.js’s execution engine is asynchronous and event…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question