[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: find first occurrence of attribute value grouped b

Subject: RE: find first occurrence of attribute value grouped by element
From: John Pallister <jpallister@xxxxxxxxxxxx>
Date: Fri, 27 Sep 2002 15:00:20 -0400
xsl value of attribute
My thanks to Andrew and James for their help with this problem.

There are probably more elegant ways to code this, but this is the completed
XSLT solution which I have implemented (posted to assist any fellow newbies
that may be interested). 
 
XSLT file:

<?xml version="1.0" ?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxsl="urn:schemas-microsoft-com:xslt">
<xsl:output method="html"/>
<xsl:key name="keyTest" match="test" use="@id" />
<xsl:key name="keyPassed" match="test[@passed='T']" use="@id" />
<xsl:key name="keyFailed" match="test[@passed='F']" use="@id" />
 
<xsl:variable name="thetests">
 <xsl:for-each select="//test"> 
      <xsl:variable name="id" select="@id"/>   
        <atest id="{@id}" Unit_id="{parent::testdata/@Unit_id}">  
        <xsl:attribute name="pft">
         <xsl:choose> 
          <xsl:when test="@passed='T' and
not(preceding-sibling::test[@id=$id]/@passed='F')">yes</xsl:when>
          <xsl:otherwise>no</xsl:otherwise>
         </xsl:choose>
        </xsl:attribute>   
       </atest>
   </xsl:for-each>
</xsl:variable>

<xsl:key name="keyPFT" match="atest[@pft='yes']" use="@id" />

<xsl:template match="/">
	<html>
	 <head><title>Summary Report</title></head>
	 <body>
	  <table border="1">
	   <tr>
	    <th>Test</th>
	    <th>Total Attempts</th>
	    <th>Total Pass</th>
	    <th>Total Fail</th>
	    <th>Pass on First Attempt</th>
	    <th>First Run Ratio</th>
	   </tr>
	   <testdata>
	    <xsl:call-template name="summary_list"/>
           </testdata>
	  </table>
	</body>
   </html>
</xsl:template>


<xsl:template match="//testdata/test[generate-id(.) =
generate-id(key('keyTest', @id))]"  name="summary_list">  
 <xsl:for-each select = "//testdata/test[@id and generate-id(.) =
generate-id(key('keyTest', @id))]" >
  <tr>   
   <!-- Display the Test Name!  -->
   <td align="center"><b><xsl:value-of select = "@id" /></b></td>
					
   <!-- Count all tests!  -->
   <td align="center"><xsl:value-of select = "count(key('keyTest',@id))"
/></td>
   <xsl:variable name="tc" select="count(key('keyTest',@id))"/>    	
			
   <!-- Count the passes!  -->
   <td align="center"><xsl:value-of select = "count(key('keyPassed',@id))"
/></td>
      	 
   <!-- Count the fails!  -->
   <td align="center"><xsl:value-of select = "count(key('keyFailed',@id))"
/></td>   
   
   <!-- Count the first run pass! --> 
   <td align="center">
    <xsl:variable name="id" select="@id"/>   
    <xsl:if test="not(msxsl:node-set($thetests)/atest[generate-id(.) =
generate-id(key('keyPFT', $id))])">
     <xsl:value-of  select = "'0'" />
     <td align="right"><xsl:value-of  select = "'0%'" /></td> 
    </xsl:if> 

   <xsl:for-each select = "msxsl:node-set($thetests)/atest[generate-id(.) =
generate-id(key('keyPFT', $id))]">    
      <xsl:value-of select = "count(key('keyPFT',$id))" />
        <xsl:if test="count(key('keyPFT',@id))">
       
    <!-- Calculate First Run Ratio -->
         <td align="right">
          <xsl:value-of  select = "format-number(count(key('keyPFT',@id))
div $tc,'###.###%')" />
         </td> 
        </xsl:if>  
     </xsl:for-each>          
    </td>     	 
  </tr>   
 </xsl:for-each>
</xsl:template>
</xsl:stylesheet>


Thanks Again!
John Pallister
jpallister@xxxxxxxxxxxx


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.