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

RE: Using the count function to count the previous s

Subject: RE: Using the count function to count the previous siblings in XLST 1.0
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Tue, 3 May 2005 12:05:10 +0100
count function in xsl
This has come up twice already in the last week. The preceding sibling of an
element is the element that appears before it in the source tree. Sorting
elements does not change their position in the source tree and therefore
does not change their siblings.

To get the position of an element in the sorted sequence, use the position()
function.

Michael Kay
http://www.saxonica.com/

> -----Original Message-----
> From: Marco Mastrocinque [mailto:mmfive@xxxxxxxxxxxxxxx] 
> Sent: 03 May 2005 11:39
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject:  Using the count function to count the previous 
> siblings in XLST 1.0
> 
> Hi All,
>        After further investigation I have I can use the following;
> 
> <xsl:when test = "position() = last()">
> <xsl:value-of select="count(preceding-sibling::employee) + 1"/>
> 
> But there is another problem, I wish to sort by two elements 
> 'OFFICE' and
> 'ENAME'. If I comment out the two xsl:sort lines, the count is correct
> (shown below). But if uncomment them, the count is incorrect. 
> Why is is this
> happening?
> 
> Thanks Marco Mastrocinque     
> 
> <xsl:for-each select="company/division">
>   <xsl:for-each select="employees/employee"> 		
> 	<!--<xsl:sort select="OFFICE"/>--> **Problem**
> 	<!--<xsl:sort select="ENAME"/>-->  **Problem** 
> 
> 	
> 
> 	
> 
> -----Original Message-----
> From: Marco Mastrocinque [mailto:mmfive@xxxxxxxxxxxxxxx] 
> Sent: Tuesday, 3 May 2005 7:57 PM
> To: (xsl-list@xxxxxxxxxxxxxxxxxxxxxx)
> Subject: Using the count function to count the previous 
> siblings in XLST 1.0
> 
> Hi All,
>        I have the following snippet of code. 
> 
>   <xsl:for-each select="company/division">
>     <xsl:for-each select="employees/employee"> 		
> 	<xsl:sort select="OFFICE"/>
> 	<xsl:sort select="ENAME"/>
> 	  <tr>				
> 	    <td>
> 		<xsl:choose>
> 		   <xsl:when test="position() != last()">
> 			<xsl:value-of select="concat(' ', @EID, 
> ', ', ENAME,
> ', ',OFFICE)"/>
> 		   </xsl:when>
> 		   <xsl:when test = "position() = last()">	
> 			<xsl:value-of select="concat(' ', @EID, 
> ', ', ENAME,
> ', ',OFFICE)"/>
> <xsl:text>&#xa;&#xa;&#xa;&#xa;Count is</xsl:text>
> 			<xsl:value-of 
> select="count(employees/employee)"/>
> </xsl:when>
> 
> 	    </td>
> </tr>
> </xsl:for-each>	   
> </xsl:for-each>
> 
> This works by displaying a whole series of data in a single 
> column in a HTML
> table. At the end of each employees/employee, with the last 
> value in this
> previously mentioned element output, I wan't to display the count of 
> 'count(employees/employee)'. It displays zero, because the system has
> already cycled all the way trough them. I want to all the 
> previous-siblings
> plus the last one. Can it be done? I want the output to be,
> 
> Element 1 (First group)
> 
> Element 2
> 
> Element 3
> Element 4 Count is 4
> 
> Element 1 (Second group)
> Element 2
> Element 3
> Element 4
> Element 5 Count is 5
> Etc...
> 
> All this a SINGLE column of a HTML table.
> 
> Thanks Marco Mastrocinque

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.