Link to home
Start Free TrialLog in
Avatar of jderting
jderting

asked on

XSLT How to Count number of records in a 'table'

Hi all,

I set up an XSLT Report that divides up a list of files by extension. (the data you are looking at is info about files that failed running through a processing tool we have)

 I am still new at this so I cheated and made an 'extension' field until I can figure that out.

Whatever the case, in the following XSLT, I have a list of files divided by extension, and a Total at the bottom (in this case, 5 files)  

However, I am not sure how to subtotal on my divisions. (in this case, there should be 2 subtotals: (pdf) 1 File, and (doc) 4 files)  I also need to subtotal the filebytes.

and, just so I dont have to do it again in the future, anyone know how to do my divisions without using my 'extension'(InputExt) field?

this sounds like it is easy to do, I'm just drawing a blank, can't seem to find an example online, and its kinda urgent, so I bumped up the points.

Since I am still learning, any comments about the format are welcome. (be nice :)

-K

first is the XML, followed by the XSLT

<?xml version='1.0'?>
<?xml-stylesheet type='text/xsl' href='File Exceptions Summary_StyleSheet.xsl'?>
<ExceptionsLog>
     <tblProcessExceptions>
          <DocID>1</DocID>
          <InputFile>C:\x\Files\x.pdf</InputFile>
          <OutputFile>C:\x\Out\sadffds\aoeui23324\OCR\y.txt</OutputFile>
          <FileBytes>3686</FileBytes>
          <FileVerified>false</FileVerified>
          <ErrorText>$E 0010 Unable to index PDF file.  Damaged or corrupt PDF file.  
Additional information: "bad xref"
getXRef -- bad xref line at 3286
</ErrorText>
          <TimeStamp>22:17:27.116 4/30/2006</TimeStamp>
          <InputExt>.pdf</InputExt>
     </tblProcessExceptions>
     <tblProcessExceptions>
          <DocID>2</DocID>
          <InputFile>C:\x\Files\aaa.doc</InputFile>
          <OutputFile>C:\x\Out\sadffds\aoeui23324\OCR\eoeo.txt</OutputFile>
          <FileBytes>448512</FileBytes>
          <FileVerified>false</FileVerified>
          <ErrorText>$E 0010 Damaged or corrupt Word document (Invalid style data)</ErrorText>
          <TimeStamp>22:17:34.326 4/30/2006</TimeStamp>
          <InputExt>.doc</InputExt>
     </tblProcessExceptions>
     <tblProcessExceptions>
          <DocID>3</DocID>
          <InputFile>C:\x\Files\iuue.doc</InputFile>
          <OutputFile>C:\x\Out\sadffds\aoeui23324\OCR\sdafddd2.txt</OutputFile>
          <FileBytes>913408</FileBytes>
          <FileVerified>false</FileVerified>
          <ErrorText>$E 0010 Damaged or corrupt Word document (Invalid style data)</ErrorText>
          <TimeStamp>22:17:34.466 4/30/2006</TimeStamp>
          <InputExt>.doc</InputExt>
     </tblProcessExceptions>
     <tblProcessExceptions>
          <DocID>4</DocID>
          <InputFile>C:\x\Files\004349\1\uuhhh.doc</InputFile>
          <OutputFile>C:\x\Out\sadffds\aoeui23324\OCR\sdafddd3.txt</OutputFile>
          <FileBytes>579584</FileBytes>
          <FileVerified>false</FileVerified>
          <ErrorText>$E 0010 Damaged or corrupt Word document (Invalid cbUPX in style)</ErrorText>
          <TimeStamp>22:17:34.617 4/30/2006</TimeStamp>
          <InputExt>.doc</InputExt>
     </tblProcessExceptions>
     <tblProcessExceptions>
          <DocID>5</DocID>
          <InputFile>C:\x\Files\004351\1\ydhttn.doc</InputFile>
          <OutputFile>C:\x\Out\sadffds\aoeui23324\OCR\sdafddd4.txt</OutputFile>
          <FileBytes>579584</FileBytes>
          <FileVerified>false</FileVerified>
          <ErrorText>$E 0010 Damaged or corrupt Word document (Invalid cbUPX in style)</ErrorText>
          <TimeStamp>22:17:34.747 4/30/2006</TimeStamp>
          <InputExt>.doc</InputExt>
     </tblProcessExceptions>
     <tblSectionInfo>
          <ProjectName>Fred</ProjectName>
          <SectionName>SectionName</SectionName>
     </tblSectionInfo>
</ExceptionsLog>







<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
    <xsl:output method="html"/>
   
    <xsl:key name="extension" match="tblProcessExceptions" use="InputExt"/>
    <xsl:template match="/">

    <xsl:apply-templates select='tblProcessExceptions'/>

    <HTML>
      <TITLE>File Exceptions Summary</TITLE>
      <BODY STYLE="font-family:Arial, helvetica, sans-serif; font-size:10pt; background-color:#EEEEEE">
            <DIV STYLE="margin-left:20px; margin-bottom:1em; font-size:10pt">
            
            <br></br>
            <table class="Project/Section ID">
                <tr>
                    <td>
                        <FONT SIZE="2">
                            Project: <b>
                                <xsl:value-of select="//tblSectionInfo/ProjectName"/>
                            </b>
                        </FONT>
                    </td>
                </tr>
                <tr>
                    <td>
                        <FONT SIZE="2">
                            Section: <b>
                                <xsl:value-of select="//tblSectionInfo/SectionName"/>
                            </b>
                        </FONT>
                    </td>
                </tr>
            </table>
             <hr></hr>
                          
            <table class="List of Files">
           
            <!-- Selectively populate Group Headings-->
            <xsl:for-each select="//tblProcessExceptions[count(. | key('extension',InputExt)[1]) = 1]">
                <xsl:variable name="extension" select="InputExt" />
               
                <tr class= "Report Fields">
                    <td class="extension">
                        <xsl:value-of select="$extension" />&#160;&#160;
                    </td>

                </tr>

                    <!-- Selectively populate fields-->
                    <xsl:for-each  select="//tblProcessExceptions">
                    <xsl:variable name="fieldEXT" select="InputExt" />
                        <xsl:if test="$fieldEXT=$extension">
                            <tr>
                                <td class="InputFileName">
                                    <FONT SIZE="2">
                                        <xsl:value-of select="InputFile"/>
                                    </FONT>
                                </td>

                                <td class="FileSize">
                                    <xsl:value-of select="FileBytes" /> Bytes
                                </td>
                            </tr>
                           
                        </xsl:if>
                    </xsl:for-each>
                   

            </xsl:for-each>
           
            </table>

             <hr></hr>

            <table class="Grand Totals">
                  <td class="spacing">
                &#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;
            </td>

            <tr class="Summary">
                <td class="File Count">
                    <FONT SIZE="2">
                        Total: <b>
                                <xsl:value-of select="format-number(count(//FileBytes), '###,###')"/> Files
                        </b>
                    </FONT>
                </td>
                <td Class="FileSize">
                    <FONT SIZE="2">
                        Total: <b>
                            <xsl:value-of select="format-number(sum(//FileBytes)div 1024, '###,###')"/> KB
                        </b>
                    </FONT>
                </td>
            </tr>            
        </table>

             <br></br>

        </DIV>

      </BODY>
    </HTML>
  </xsl:template>
   
</xsl:stylesheet>

Avatar of rdcpro
rdcpro
Flag of United States of America image

Just count using your key:

count(key('extension',InputExt))

If the current goup is "pdf" then this looks like:

count(key('extension','pdf'))

which will return the count of records with "pdf" in the InputExt.

Regards,
Mike Sharp
Avatar of jderting
jderting

ASKER

That's great! thank you :)

Please pardon my newbieness, but how would I count the FileBytes?


-K
ASKER CERTIFIED SOLUTION
Avatar of rdcpro
rdcpro
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial