Connecting Tech Pros Worldwide Forums | Help | Site Map

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

Newbie
 
Join Date: Oct 2007
Posts: 21
#1: Oct 5 '08
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

Dormilich's Avatar
Moderator
 
Join Date: Aug 2008
Location: Leipzig, Germany
Posts: 3,661
#2: Oct 6 '08

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


just put the whole condition in square brackets

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

regards
Newbie
 
Join Date: Oct 2007
Posts: 21
#3: Oct 7 '08

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


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>
Quote:

Originally Posted by Dormilich

just put the whole condition in square brackets

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

regards

Dormilich's Avatar
Moderator
 
Join Date: Aug 2008
Location: Leipzig, Germany
Posts: 3,661
#4: Oct 7 '08

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


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
Reply