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

RE: A better way to build a comma-delimited list

Subject: RE: A better way to build a comma-delimited list
From: sara.mitchell@xxxxxxxxx
Date: Wed, 15 May 2002 13:28:43 -0400
sql comma delimited list
This may be a naive answer (given the previous posts), 
but it seems like you're simply looking at the addition
of text the wrong direction. You need to add ", " *before*
the 2nd, 3rd (and ultimately all but the first) columns. 
Would it work better if you did the test *before* the 
<xsl:value-of> and tested to see if this is not the first? 
If so, add the comma and space and then output the value of
the column. 

Sara

> -----Original Message-----
> From: John Sands [mailto:WonkoWatson@xxxxxxxxx]
> Sent: Tuesday, May 14, 2002 7:35 PM
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject:  A better way to build a comma-delimited list
> 
> 
> I have some XSLT that builds a SQL select statement from several input
> documents. Here's a fragment that builds the column list by getting
> each distinct column name from a separate file ($pbsdef) and checking
> that is is defined in another file (referenced by variable $dbdef).
> 
>    <xsl:text>select </xsl:text>
>    <xsl:for-each 
> select="document($pbsdef)/pbsdef/column[not(@dbcolumn=precedin
> g-sibling::column/@dbcolumn)]">
>       <xsl:variable name="p" select="position()"/>
>       <xsl:variable name="l" select="last()"/>
>       <xsl:variable name="dbcolumn" select="@dbcolumn"/>
>       <xsl:for-each select="$dbdef">
>          <xsl:if test="key('dbdef-cols', $dbcolumn)">
>             <xsl:value-of select="$dbcolumn"/>
>             <xsl:if test="$p &lt; $l">
>                <xsl:text>, </xsl:text>
>             </xsl:if>
>          </xsl:if>
>       </xsl:for-each>
>    </xsl:for-each>
> 
> The output of this fragment might be:
> 
>  select col1, col2, col3
> 
> This all works fine, except for one case - where the last column is
> not found in the $dbdef file (where the 'if test=key' fails). Then I
> get:
> 
>  select col1, col2,
> 
> The position() < last() test doesn't work here. Can someone see a
> better way to avoid that last comma?
> 
> Thanks,
> John Sands
> 
> 
>  XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
> 

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

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.
Email
First Name
Last Name
Company
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.