I wanna know how to count the number of an attribute with particular values??

Roseanne Zhang

Here is a complete answer for you!

Q. Can we do statistics on a specific attribute value?
For examplw, how to get the statistics of status attribute of result element:

	<result status="-1" >aaa</result>
	<result status="-5" >bbb</result>
	<result status="-1" >ccc</result>
	<result status="-5" >ddd</result>
	<result status="-5" >lll</result>
	<result status="-6" >vvv</result>
	<result status="-1" >vvv</result>
A: Using XSLT Grouping. Here is using muenchain method.
XSLT sourece
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:output method="text" />
  <xsl:key name="stvalkey" match="//result" use="@status" />
  <xsl:template match="/">
    <xsl:for-each select="//result/" >
      <xsl:variable name="tmp" >
        <xsl:value-of select="./@status" />
      <xsl:if test="generate-id(.) = generate-id(key('stvalkey',$tmp)[1])">
        <xsl:value-of select="$tmp" />:<xsl:value-of select="count(key('stvalkey',$tmp))" /><xsl:text>
  <xsl:template match="text()" />
Text result to show the statistics
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



About | Sitemap | Contact