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

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • gagonm
    New Member
    • Oct 2007
    • 26

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

    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'])


    Code:
    <?xml version="1.0" encoding="utf-8"?>
    <test lastActivityTime="9/24/2008 9:34:40 AM">
      <SpecialtyInfo>
        <Specialty name="Outdoor" id="3" isSpecialist="false"  ></Specialty>
        <Specialty name="Shopping" id="4" isSpecialist="false" ></Specialty>
        <Specialty name="Shopping" id="5 isSpecialist="true" ></Specialty>
      </SpecialtyInfo>
    </test>




    Thanks
    Jalaj
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #2
    just put the whole condition in square brackets

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

    regards

    Comment

    • gagonm
      New Member
      • Oct 2007
      • 26

      #3
      Hey It didn't work out. It always give me same result.
      below is snippet of my xslt.


      Code:
      <xslt:value-of select="count(//Specialty/Specialty[@isSpecialist=true])"/>
            
            <xslt:choose>        
              <xslt:when test="count(//Specialty/Specialty[@isSpecialist='true'])>0">
                
                <xslt:apply-templates select="/Testing/SpecialtyInfo/Specialty"></xslt:apply-templates>
              </xslt:when>
              <xslt:otherwise>
                
                <xslt:text>None identified as yet </xslt:text>  
              </xslt:otherwise>        
            </xslt:choose>
      Originally posted by Dormilich
      just put the whole condition in square brackets

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

      regards

      Comment

      • Dormilich
        Recognized Expert Expert
        • Aug 2008
        • 8694

        #4
        Code:
        <xslt:value-of select="count(//Specialty/Specialty[@isSpecialist='true'])"/>
        this won't work since there are no <Specialty> elements inside <Specialty>.

        try this one
        Code:
        <xslt:value-of select="count(//Specialty[@isSpecialist='true'])"/>
        regards

        Comment

        Working...