[xsl] starts-with on more than one item

Subject: [xsl] starts-with on more than one item
From: "Ronnie Royston" <rhroyston@xxxxxxxxx>
Date: Fri, 30 May 2008 11:07:06 -0500
Dr. Carlisle, Dr, Kay, I am soooo excited.  Check this out.  I did it
all on my own (with help from Michael's book).  So, I needed to
output, "Your proposal includes this, that, and the other."  David got
me on the right track with outputting the name of all the skus
retrieved from the document() function.  Well, I needed to put the
commas and an "and, " before the last thing in the series.  Well,
below is what I put together and it works!  Maybe you have a more
efficient way to do this?  I am just so excited that I could do this!
Woo Hoo!!!  My output is - Your proposal includes Cisco routers, Cisco
switches, and Cisco Linecards."  I can change the mySkus.xml file to
include other parts and doggonit it works!  Way cool.

<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: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*" select="for $s in $skus
return key('sku',$s[document('mySkus.xml')/skus/sku[starts-with(.,$s)]],$root)/name"
/>


<xsl:template match="/">
 <html>
 <head>
  <title>Test Document</title>
 </head>
 <body>
  <H1>Executive Summary</H1>
<p>Your proposal includes

<xsl:for-each select="$names">
<xsl:choose>
	<xsl:when test="position()=last()">
		<xsl:value-of select="concat(', and ', ., '.')"/>
	</xsl:when>
	<xsl:when test="position()=1">
		<xsl:value-of select="concat(' ', .)"/>
	</xsl:when>
	<xsl:otherwise>
		<xsl:value-of select="concat(', ', .)"/>
	</xsl:otherwise>
</xsl:choose>
</xsl:for-each>

</p>

 </body>
 </html>
</xsl:template>
</xsl:stylesheet>

OK, I'll stop boring you guys with my elementary work now...  But I'll
be back with some more difficult questions!

Current Thread