Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 23rd, 2006, 09:59 AM
Authorized User
 
Join Date: Jun 2006
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Default Count Function returns strange value

I am having a problem with the count function, which I am using within a group function.

Here is the xml I am trying to convert:
Code:
<dataroot>
<pavement_x0020_Conditions>
<BranchID>TWAWK</BranchID>
<Name>TAXIWAY A</Name>
<Condition>100</Condition>
<Method>PCI</Method>
<DATE>2006-10-05T00:00:00</DATE>
<SAMPLES>50</SAMPLES>
<NetworkID>WICKENBURG</NetworkID>
<SectionID>10</SectionID>
<Surface>AC</Surface>
<_Length>2164.08000000866</_Length>
<_Width>10.6680000000427</_Width>
<_Area_x0020_Adjustment>0</_Area_x0020_Adjustment>
</pavement_x0020_Conditions>
where there are several different possible values for <Surface> and hundreds of <pavement...> nodes

Here is my XSL file:
Code:
<xsl:template match="dataroot">
  <xsl:for-each-group select="pavement_x0020_Conditions" group-by="Surface">
    <xsl:sort select="Surface"/>
      <record>
        <Type><xsl:value-of select="Surface"/></Type>
        <Sections><xsl:value-of select="count(SectionID)"/></Sections>
      </record>
  </xsl:for-each-group>
    </main>
</xsl:template>
And this is what it puts out:
Code:
<record>
        <Type>AC</Type>
        <Sections>1</Sections>
    </record>
    <record>
        <Type>APC</Type>
        <Sections>1</Sections>
    </record>
when there are dozens of AC and APC Sections. I think the problem has something to do with the grouping, but as far as I can tell, it should work. Any help would be greatly appreciated.

Thanks
 
Old June 23rd, 2006, 10:07 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

count(SectionID) means count(./SectionID) - the number of SectionID element children of the context node. Perhaps you meant

count(current-group()/SectionID) - the number of SectionID children of the elements in the current group.

Or perhaps you just want count(current-group()) - the size of the curren group.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old June 23rd, 2006, 10:13 AM
Authorized User
 
Join Date: Jun 2006
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Default

For the record: That was exactly the problem. Both "count(current-group()/SectionID)" and "count(current-group())" returned the value I needed.

Thank you very much!





Similar Threads
Thread Thread Starter Forum Replies Last Post
function returns Incorrect syntax keyvanjan ASP.NET 2.0 Professional 1 July 29th, 2007 10:36 AM
Running Count Function jdbash1 Access VBA 1 June 7th, 2007 11:03 AM
Help With Count Function darrenb Access VBA 3 May 2nd, 2007 06:52 PM
is there any in built function to count page count g.tamilselvan MySQL 1 February 15th, 2006 07:43 AM
Problem with setTimeout and function returns greg.webb Javascript How-To 5 August 31st, 2005 02:00 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.