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

Re: How to find unique element.

Subject: Re: How to find unique element.
From: David Carlisle <davidc@xxxxxxxxx>
Date: Tue, 18 May 1999 14:04:35 +0100 (BST)
xsl unique element
> <xsl:functions ns="jjc" type="text/javascript"> 
>      ~/some processing instructions 
> </xsl:functions>
> would be one way.

Script may work, but it may be worth seeing how far you can get without

The original questions were 

> Problems:
> 1) How do i find out unique projectcodes?
> 2) How to display the total hours put in by all the employees in a
>    particular project?

which I think means that you want something like the following
for the example XMl you posted?

  bash-2.01$ xt p2.xml p.xsl

  Project p1
  Employee: 1,  Hours: 10
  Employee: 2,  Hours: 14
  Total: 24
  Project p2
  Employee: 1,  Hours: 8
  Employee: 2,  Hours: 6
  Total: 14
  Project p3
  Employee: 2,  Hours: 12
  Total: 12

If so, you may want to play with the xml code at the end of this msg.



<xsl:template match="company">
  <xsl:apply-templates mode="find" select="Employee/project/@pcode">

<xsl:template mode="find" match="@pcode">
<!-- grab first occurrence -->
 <xsl:variable name="x" expr="."/>
 <xsl:if test="not(from-following(*[@pcode=$x]))">
  Project <xsl:value-of select="$x"/>
 <xsl:apply-templates select="/from-descendants(project[@pcode=$x][1])">
  <xsl:param name="hlours" expr="0"/>
  <xsl:param name="x" expr="$x"/>

<xsl:template match="project">
 <xsl:param-variable name="x" />
 <xsl:param-variable name="hours" />
  Employee: <xsl:value-of select="../@empcode"
/>,  Hours: <xsl:value-of select="duration/@hours"/>
 <xsl:apply-templates select="from-following(project[@pcode=$x][1])">
  <xsl:param name="hours" expr="$hours+duration/@hours"/>
  <xsl:param name="x" expr="$x"/>
  <xsl:if test="not(from-following(project[@pcode=$x]))">
  Total: <xsl:value-of select="$hours+duration/@hours"/>



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

Current Thread


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.
First Name
Last Name
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.