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

Conditionally Sum an Attribute

Subject: Conditionally Sum an Attribute
From: "Ronnie Royston" <rhroyston@xxxxxxxxx>
Date: Sat, 31 May 2008 19:03:44 -0500
 Conditionally Sum an Attribute
Using Saxon-B 9.0 on Windows.  I am really trying and could use a
nudge (or shove) in the right direction.  I posted on this problem
before and have grown the problem.  I'm running a stylesheet against a
well-formed braindump of my knowledge on each type of thing that I
sell during my day job (routers, switches, etc.) and am using the
document('mySkus.xml') function to determine what parts of my
knowledge.xml to output to "Scope of Work.html".  The idea is that a
custom scope of work is generated based on what I am selling (what is
in mySkus.xml).  Snippets of both XML files are at the bottom of this

I can't figure out how to concatenate the sum of all mySku's
@quantities that share a starts-with <name> from my knowledge, with
their <name> from my knowledge to generate the desired output.  For
example, 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."

Here's my unsuccessful stylesheet.  The problem lies in the variable
names "names".  Please understand this is the last attempt - I was
probably close on one of the many attempts I've made (lol).  One last
thing - don't worry about the "s" on plural items - I'll save that
battle for another day:

<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" select="for $s in $skus return concat(

<xsl:template match="/">

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



<?xml version="1.0"?>
<sku quantity="3">WS-C3750G-24PS-S</sku>
<sku quantity="7">CP-7937G</sku>
<sku quantity="10">CP-7941G</sku>
<sku quantity="5">WS-X6708-10G-3C</sku>
<sku quantity="2">CISCO2811-V/K9</sku>

<?xml version="1.0"?>
		<name>Cisco phones</name>
		<discovery>call forwarding destinations</discovery>
		<verify>Out-dialing and In-dialing to a single phone in each
configured class of service ensures a working dialplan and handset
configuration.  </verify>
		<responsibility>unbox, assemble, and place phones at their final
		<name>Cisco Analog Telephone Adapters</name>
		<discovery>directory number assignments</discovery>
		<verify>In-dialing to a fax machine is tested, if applicable.  </verify>
		<name>Cisco routers</name>
		<discovery>routing protocols to be enabled</discovery>
		<verify>ping an IP address on a local interface</verify>

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.