Connecting Tech Pros Worldwide Help | Site Map

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

  #1  
Old October 5th, 2008, 07:06 PM
Newbie
 
Join Date: Oct 2007
Posts: 21
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
  #2  
Old October 6th, 2008, 05:07 AM
Dormilich's Avatar
Moderator
 
Join Date: Aug 2008
Location: Leipzig, Germany
Posts: 3,492
Provided Answers: 10

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


just put the whole condition in square brackets

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

regards
  #3  
Old October 7th, 2008, 07:13 AM
Newbie
 
Join Date: Oct 2007
Posts: 21

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
  #4  
Old October 7th, 2008, 08:24 AM
Dormilich's Avatar
Moderator
 
Join Date: Aug 2008
Location: Leipzig, Germany
Posts: 3,492
Provided Answers: 10

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