469,366 Members | 2,236 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,366 developers. It's quick & easy.

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

26
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 21782
Dormilich
8,652 Expert Mod 8TB
just put the whole condition in square brackets

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

regards
Oct 6 '08 #2
gagonm
26
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,652 Expert Mod 8TB
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

Post your reply

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

Similar topics

5 posts views Thread by inquirydog | last post: by
25 posts views Thread by Mike | last post: by
3 posts views Thread by abhishek.smu | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by suresh191 | last post: by
1 post views Thread by Marylou17 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.