Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


[xsl] Conditionally Sum an Attribute

From: "Ronnie Royston" <rhroyston@--------->
To:
Date: 6/1/2008 12:04:00 AM
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
email.

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(
sum(key('sku',$s[document('mySkus.xml')/skus/sku[starts-with(.,$s)]],@quantity),
key('sku',$s[document('mySkus.xml')/skus/sku[starts-with(.,$s)]],$root)/name)"
/>

<xsl:template match="/">

<xsl:result-document href="file:///C:\Saxon\bin\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>


mySkus.xml:
<?xml version="1.0"?>
<skus>
<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>
</skus>

knowledge.xml
<?xml version="1.0"?>
<knowledge>
	<part>
		<code>CP-</code>
		<name>Cisco phones</name>
		<abbreviation>handsets</abbreviation>
		<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
locations</responsibility>
	</part>
	<part>
		<code>ATA186-</code>
		<name>Cisco Analog Telephone Adapters</name>
		<abbreviation>ATA</abbreviation>
		<discovery>directory number assignments</discovery>
		<verify>In-dialing to a fax machine is tested, if applicable.  </verify>
	</part>
	<part>
		<code>CISCO</code>
		<name>Cisco routers</name>
		<abbreviation>routers</abbreviation>
		<discovery>routing protocols to be enabled</discovery>
		<verify>ping an IP address on a local interface</verify>
	</part>
</knowledge>


transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent