开发者

How to use the count() function is XSL - trying to count the amount of "A"s there are in a report

开发者 https://www.devze.com 2023-03-07 12:34 出处:网络
I\'m trying to count the amount of A\'s there are in a school report. Here is the report: <class>

I'm trying to count the amount of A's there are in a school report.

Here is the report:

<class>
  <student>
   开发者_开发百科 <first-name>Jane</first-name>
    <last-name>Doe</last-name>
    <grade>A</grade>
  </student>
  <student>
    <first-name>John</first-name>
    <last-name>Smith</last-name>
    <grade>B</grade>
  </student>
  <student>
    <first-name>Harry</first-name>
    <last-name>Grandson</last-name>
    <grade>A</grade>
  </student>
  <student>
    <first-name>Lacy</first-name>
    <last-name>Jones</last-name>
    <grade>C</grade>
  </student>
</class>

How do I get the number of A's in the report?

I came up with:

<xsl:value-of select="count(/class/student/grade)"/>

But that counts everything - So I tried to get only the A's with this:

<xsl:value-of select="count(/class/student/grade/A)"/>

But this doesn't work either.

I also tried this:

<xsl:value-of select="count(/class/student[grade=A])"/>

But that doesn't work either - what do you guys think?


<xsl:value-of select="count(/class/student[grade='A'])"/>


You can also use:

count(/class/student/grade[text()="A"])
0

精彩评论

暂无评论...
验证码 换一张
取 消