xsl-list
[Top] [All Lists]

Re: [xsl] replacing text in output

2006-03-16 05:12:59
On 3/16/06, garry(_at_)skegnessgrammar(_dot_)org 
<garry(_at_)skegnessgrammar(_dot_)org> wrote:
The following template generates sql. However, there may or may not be
commas at the end of each statement and this is throwing my database
adapter off.
ie. this may occur which throws an error - ,attribute,)
I need to eliminate these trailing commas in the output. So far I am
trying to use the replace() function but have had no luck. Is there an
easy way to alter the output after the transform.

Nice stylesheet you have there.....

Replace:

<xsl:for-each select="CTfile/CTFpupilData/Pupil">
insert into studentdetails(
   <xsl:if test="UPN"> upn,</xsl:if>
   <xsl:if test="Surname"> surname ,</xsl:if>
   <xsl:if test="Forename"> forename , </xsl:if>
   [lots more of the same]

With templates:

<xsl:template match="...">
  <xsl:text>insert into studentdetails( </xsl:text>

  <xsl:for-each select="CTfile/CTFpupilData/Pupil/*">
    <xsl:apply-templates select="."/>
    <xsl:if test="position() != last()">, </xsl:if>
  </xsl:for-each>
</xsl:template>

<xsl:template match="UPN"> upn </xsl:template>
<xsl:template match="Surname"> surname </xsl:template>
<xsl:template match="Forename"> forename </xsl:template>

Hopefully you get the idea.
Fantastic, I tried the position() != last() thing but could not get the
sequence right. This sorts it, thanks.
regards
garru


--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: 
<mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--





--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

<Prev in Thread] Current Thread [Next in Thread>