[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: How to find 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 scripting. 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 ====================== bash-2.01$ If so, you may want to play with the xml code at the end of this msg. David <xsl:stylesheet xmlns:xsl="http://www.w3.org/XSL/Transform/1.0" result-ns=""> <xsl:template match="company"> <xsl:apply-templates mode="find" select="Employee/project/@pcode"> </xsl:apply-templates> </xsl:template> <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:apply-templates> </xsl:if> </xsl:template> <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:apply-templates> <xsl:if test="not(from-following(project[@pcode=$x]))"> Total: <xsl:value-of select="$hours+duration/@hours"/> ====================== </xsl:if> </xsl:template> </xsl:stylesheet> XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|