Re: [xsl] Conditionally Sum an Attribute

Subject: Re: [xsl] Conditionally Sum an Attribute
From: David Carlisle <davidc@xxxxxxxxx>
Date: Sun, 1 Jun 2008 01:58:25 +0100
> I want to output "DataVox is offering Big Momma's Cafe
> project services at a fixed price for the installation of 1 router, 3
> switches, and 7 phones."

That doesn't seem to match the posted input, it's always helpful if you
say the expected result from a given input, I get



  17 Cisco phones, and 2 Cisco routers.


> <xsl:result-document href="file:///C:\Saxon\bin\proposal.html">

always use / not \ it's a URI not a windows file path.



<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
 xmlns:xs="http://www.w3.org/2001/XMLSchema"; exclude-result-prefixes="xs"
 version="2.0" >
<xsl:param name="customer">Customer</xsl:param>
<xsl:key name="sku" match="knowledge/part" use="code" />

<xsl:variable name="root" select="/"/>
<xsl:variable name="skus" as="xs:string*"
select="distinct-values(/knowledge/part/code)" />

<xsl:variable name="names" as="xs:string*">
 <xsl:for-each select="$skus">
  <xsl:variable name="x" select="document('mySkus.xml')/skus/sku[starts-with(.,current())]"/>
  <xsl:sequence select="
			key('sku',current()[$x],$root)/(concat(sum($x/@quantity),' ',name))"
		/>
 </xsl:for-each>
</xsl:variable>
<xsl:template match="/">


<xsl:result-document href="proposal.html">
 <html>
 <head>
  <title>Project Services from DataVox</title>
 </head>
 <body>
  <H1>Executive Summary</H1>
<H2>Project Services Summary</H2>
<H3>Introduction</H3>
<p>
DataVox is offering <xsl:value-of select="$customer"/> project
services at a fixed price for the installation of
<xsl:for-each select="$names">
<xsl:choose>
	<xsl:when test="position()=1">
		<xsl:value-of select="concat(' ', .)"/>
	</xsl:when>
	<xsl:when test="position()=last()">
		<xsl:value-of select="concat(', and ', ., '. ')"/>
	</xsl:when>
	<xsl:otherwise>
		<xsl:value-of select="concat(', ', .)"/>
	</xsl:otherwise>
</xsl:choose>
</xsl:for-each>

</p>

 </body>
 </html>
</xsl:result-document>
</xsl:template>
</xsl:stylesheet>

________________________________________________________________________
The Numerical Algorithms Group Ltd is a company registered in England
and Wales with company number 1249803. The registered office is:
Wilkinson House, Jordan Hill Road, Oxford OX2 8DR, United Kingdom.

This e-mail has been scanned for all viruses by Star. The service is
powered by MessageLabs. 
________________________________________________________________________

Current Thread