Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

XSL to count elements meeting criteria

Posted on 2004-09-17
5
Medium Priority
?
214 Views
Last Modified: 2012-06-27
I need a way to get the total number of val elements and the number of them that are between lo-val and hi-val inclusive. In the following example the answers should be 9 total with 4 in-between.

Thanks!

<doc>
<parms>
<lo-val>100</lo-val>
<hi-val>120</hi-val>
</parms>
<val>130</val>
<val>120</val>
<val>100</val>
<val>10</val>
<val>110</val>
<val>11</val>
<val>140</val>
<val>115</val>
<val>160</val>
</doc>
0
Comment
Question by:MajorBigDeal
5 Comments
 
LVL 4

Expert Comment

by:Kaarthick
ID: 12090363
0
 
LVL 11

Author Comment

by:MajorBigDeal
ID: 12090580
Thanks, I looked at it and tried to seach for an explanation of how it works but couldn't find one. If this is a good approach, can you (or anyone) please  relate it to the example I posted? I'm sorry I don't understand it but I'm new at XSL.

Thanks again!
0
 
LVL 19

Accepted Solution

by:
ramazanyich earned 1200 total points
ID: 12090861
Use following xsl stylesheet:

<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:template match="/">
Total: <xsl:value-of select="count(doc/val)"/>
In between: <xsl:value-of select="count(/doc/val[node() &gt;= ../parms/lo-val and node() &lt;= ../parms/hi-val]  )"/>
</xsl:template>
</xsl:stylesheet>
0
 
LVL 7

Expert Comment

by:J_Mak
ID: 12091419
This would most certainly give you the answer. Try it out.

<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
   <xsl:template match="/">
      <!-- this will give you the total number of val elements -->
      <xsl:value-of select="count(//val)"/>
      <!-- this will give you the number of val elements that fall inside the bracket -->
      <xsl:value-of select="count(//val[child::*[1] &lt;= //hi-val] and child::*[1] &gt;= //lo-val)"/>
   </xsl:template>
</xsl:stylesheet>

Hope that helps
0
 
LVL 11

Author Comment

by:MajorBigDeal
ID: 12092781
ramazanyich, that worked, I'll try to apply it for real on Monday - Thanks!

J Mak - your version gave me the following error. Maybe due to an incompatibility in parsers.  

Expression does not return a DOM node. -->count(//val[child::*[1] <= //hi-val] and child::*[1] >= //lo-val)<--

Thanks all for your help!
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

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

The Client Need Led Us to RSS I recently had an investment company ask me how they might notify their constituents about their newsworthy publications.  Probably you would think "Facebook" or "Twitter" but this is an interesting client.  Their cons…
The Confluence of Individual Knowledge and the Collective Intelligence At this writing (summer 2013) the term API (http://dictionary.reference.com/browse/API?s=t) has made its way into the popular lexicon of the English language.  A few years ago, …
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…

885 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