473,714 Members | 2,328 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

XSLT ::Get Count of nodes in xml matching certain condition

26 New Member
Hi

I have simple xml .Here in XSL1.0 ,I want to get count of all speciality tag where attribute isSpecialist= false. Similarily count of all speciality tag with isspecialist attribute value as true.

I used this but this doesn't work
count(/test/SpecialtyInfo/Specialty/@isSpecialist['true'])


Expand|Select|Wrap|Line Numbers
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <test lastActivityTime="9/24/2008 9:34:40 AM">
  3.   <SpecialtyInfo>
  4.     <Specialty name="Outdoor" id="3" isSpecialist="false"  ></Specialty>
  5.     <Specialty name="Shopping" id="4" isSpecialist="false" ></Specialty>
  6.     <Specialty name="Shopping" id="5 isSpecialist="true" ></Specialty>
  7.   </SpecialtyInfo>
  8. </test>




Thanks
Jalaj
Oct 5 '08 #1
3 22944
Dormilich
8,658 Recognized Expert Moderator Expert
just put the whole condition in square brackets

count(//Specialty/[@isSpecialist = 'true'])

regards
Oct 6 '08 #2
gagonm
26 New Member
Hey It didn't work out. It always give me same result.
below is snippet of my xslt.


Expand|Select|Wrap|Line Numbers
  1. <xslt:value-of select="count(//Specialty/Specialty[@isSpecialist=true])"/>
  2.  
  3.       <xslt:choose>        
  4.         <xslt:when test="count(//Specialty/Specialty[@isSpecialist='true'])>0">
  5.  
  6.           <xslt:apply-templates select="/Testing/SpecialtyInfo/Specialty"></xslt:apply-templates>
  7.         </xslt:when>
  8.         <xslt:otherwise>
  9.  
  10.           <xslt:text>None identified as yet </xslt:text>  
  11.         </xslt:otherwise>        
  12.       </xslt:choose>
just put the whole condition in square brackets

count(//Specialty/[@isSpecialist = 'true'])

regards
Oct 7 '08 #3
Dormilich
8,658 Recognized Expert Moderator Expert
Expand|Select|Wrap|Line Numbers
  1. <xslt:value-of select="count(//Specialty/Specialty[@isSpecialist='true'])"/>
this won't work since there are no <Specialty> elements inside <Specialty>.

try this one
Expand|Select|Wrap|Line Numbers
  1. <xslt:value-of select="count(//Specialty[@isSpecialist='true'])"/>
regards
Oct 7 '08 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

3
3895
by: Lizard | last post by:
OK, total newbie here, so this may be a mind-numbingly dumb question AND I may be phrasing it badly. I have an xsl:template which looks like this: <xsl:template match="LoanRecord"> <hr> <xsl:number count="LoanRecord" format="1"/><br/> Loan ID:<xsl:value-of select="loan_no"> </xsl:value-of><br/> Calculated CLTV:<xsl:value-of select="format-number (curr_balance div
5
3556
by: Marcel Akkerman | last post by:
Hi, Does anyone have a clue how to reduce the number of nodes using XSLT? When outputing all nodes in order I could just use <xsl:for-each select="name"> But what if I, besides sorting and grouping, I also output conditionally? <xsl:for-each
5
9553
by: inquirydog | last post by:
Hi- Does anyone know a way to compare whether two nodes contain the same information in xslt (the name, attributes, and all content recursivly should be the same. I am interested in the case where node ordering matters, and also the case where it doesn't, but perhaps that is an advanced topic). Ideally the method should be available to xpath expressions, so I think that creating new templates which compare nodes will not work (well,...
4
5742
by: gualtmacchi | last post by:
I'm processing an XML input file getting a plain text file where from M nodes I got N output lines... It's not relevant but the input file is a recordset coming from a database and the output is an EDI message set. Now I need to put into the output file also some information regarding just the output file itself and not the input one. And it cannot be expressed in terms of input information. For example I need to determine and write how...
6
1830
by: Neal | last post by:
Hi All, I used an article on XSLT and XML and creating a TOC written on the MSDN CodeCorner. ms-help://MS.VSCC.2003/MS.MSDNQTR.2003FEB.1033/dncodecorn/html/corner042699.htm However, it did'nt quite answer all my questions. How would one create a 3 level TOC when each item level / node was differently named (They used Template match and for-each, but the template match worked as on a 3 level structure they usedf the same named xml...
25
5156
by: Mike | last post by:
I have a regular expression (^(.+)(?=\s*).*\1 ) that results in matches. I would like to get what the actual regular expression is. In other words, when I apply ^(.+)(?=\s*).*\1 to " HEART (CONDUCTION DEFECT) 37.33/2 HEART (CONDUCTION DEFECT) WITH CATHETER 37.34/2 " the expression is "HEART (CONDUCTION DEFECT)". How do I gain access to the expression (not the matches) at runtime? Thanks, Mike
3
2789
by: abhishek.smu | last post by:
Given an XML like: <root> <node>8</node> <node>21</node> <node>-7</node> <node>13</node> <node>43</node> <node>2</node> </root>
4
1994
by: raghunandanbasf | last post by:
Hi friends, I am new to the xslt when i am doing ,I have struck in middle. Q.As per example:we are having the xml structure like this <a> <b>-----</b> <c>-----</c> <d>-----</d> </a>
0
8802
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
8711
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
9314
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
9075
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,...
1
6634
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5948
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();...
1
3158
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
2
2522
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2111
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.