| Subject: [xsl] A better way to build a comma-delimited list From: John Sands <WonkoWatson@xxxxxxxxx> Date: Tue, 14 May 2002 22:34:47 -0400 | 
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=preceding-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 < $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
| Current Thread | 
|---|
| 
 | 
| <- Previous | Index | Next -> | 
|---|---|---|
| RE: [xsl] read records from databas, Stuart Celarier | Thread | Re: [xsl] A better way to build a c, Joerg Heinicke | 
| Re: [xsl] XSLT/XPath 2.0 (was "Iden, Elliotte Rusty Harol | Date | RE: [xsl] read records from databas, Mingqiang Yu | 
| Month |