Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: [xsl] Grouping & Counting Attribures

From: David Carlisle <davidc@--------->
To:
Date: 3/2/2009 11:42:00 PM
> ??? why didn't this need a [1] near end to get first occurance ??? 

you would in xslt2 (or get an error if you passed two nodes to
generate-id) but in xslt 1 (or xslt2 in bbackwards compat mode)
string functions have a "first node" behaviour, they silently discard
all but the first node passed to them, so generate-id(foo) is the same
as generate-id((foo)[1]) in xslt 1.

In xslt2 though you wouldn't do this at all, you'd use for-each-group.


>   <xsl:variable name="findings" select=key('audits', @AuditName)/>
not well formed.


> ### above line does not work, was meant to go with  above. ###
in what way doesn't it work? It works for me 9as in produces te output
you say you want)

> ### this states what I am trying to do, but I know syntax is wrong ###

actually not, without the line above (which uses correct syntax) I
probably wouldn't have guessed what was intended here.

> ### cannot select on the 2D list returned by key ###
Not sure what you mean here.

If I make your xsl well formed and change the 'InReview' test to use the
syntax you used for  'ActionPlan' I get 

something that appears to match



> Audit  # Rows  ActionPlan  InReview ..........
> CashboxII 2      1           1
> SPN       2      2           0


<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
 

<xsl:output method="html"/>

<xsl:key name="audits" match="Row" use="@AuditName" />
<xsl:template match="/dsQueryResponse/Rows">
  <table>
    <tr><th>AUDIT</th><th># Rows</th>
    	<th># ActionPlan</th><th># InReview</th>
    	<th># FollowUp</th><th># Closed</th>
    </tr>
    <xsl:apply-templates
      select="*[@AuditName and
                generate-id(.)=generate-id(key('audits', @AuditName))]" />
  </table>
</xsl:template>

<xsl:template match="*[@AuditName]">
  <xsl:variable name="findings" select="key('audits', @AuditName)"/>
  <tr>
    <td><xsl:value-of select="@AuditName" /></td>
    <td><xsl:value-of select="count(key('audits', @AuditName))" /></td>
    <td><xsl:value-of select="count($findings[@State='ActionPlan'])" /></td>
    <td><xsl:value-of select="count($findings[@State='InReview'])" /></td>
      </tr>
</xsl:template>

</xsl:stylesheet>


$ saxon ds.xml ds.xsl

<table>
   <tr>
      <th>AUDIT</th>
      <th># Rows</th>
      <th># ActionPlan</th>
      <th># InReview</th>
      <th># FollowUp</th>
      <th># Closed</th>
   </tr>
   <tr>
      <td>Cashbox II</td>
      <td>2</td>
      <td>1</td>
      <td>1</td>
   </tr>
   <tr>
      <td>SNP</td>
      <td>2</td>
      <td>2</td>
      <td>0</td>
   </tr>
</table>


David



________________________________________________________________________
The Numerical Algorithms Group Ltd is a company registered in England
and Wales with company number 1249803. The registered office is:
Wilkinson House, Jordan Hill Road, Oxford OX2 8DR, United Kingdom.

This e-mail has been scanned for all viruses by Star. The service is
powered by MessageLabs. 
________________________________________________________________________


transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent