[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

RE: RE: RE: RE: [xsl] Malformed (??) XML and XML 2 SQL XSLTtransformation


Subject: RE: RE: RE: RE: [xsl] Malformed (??) XML and XML 2 SQL XSLTtransformation
From: cknell@xxxxxxxxxx
Date: Fri, 14 Nov 2003 16:10:11 -0500

I figured out how to fix the excess white space and I noticed that I had inadvertently set the output to "xml". In this version it is correctly set to "text".

<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
 <xsl:output method="text" indent="yes" encoding="UTF-8" />

 <xsl:template match="/">
   <xsl:for-each select="Orders/Customer/Template/Fields[@FieldName='User Login ID']">
<xsl:text>INSERT INTO ORDERS("</xsl:text><xsl:value-of select="normalize-space(@FieldName)"/><xsl:text>"</xsl:text>
     <xsl:choose>
       <xsl:when test="following-sibling::*[1][@FieldName != 'User Login ID']">
         <xsl:variable name="fs-number" select="2" />
         <xsl:call-template name="column-name">
           <xsl:with-param name="fs1" select="$fs-number" />
         </xsl:call-template>
<xsl:text>VALUES("</xsl:text><xsl:value-of select="normalize-space(.)"/><xsl:text>"</xsl:text>
         <xsl:call-template name="column-value">
           <xsl:with-param name="fs1" select="$fs-number" />
         </xsl:call-template>
       </xsl:when>
     </xsl:choose>
     <xsl:text>
</xsl:text>
   </xsl:for-each>
 </xsl:template>

 <xsl:template name="column-name">
   <xsl:param name="fs1" />
   <xsl:variable name="fs-number" select="$fs1 + 1" />
<xsl:text>,"</xsl:text><xsl:value-of select="normalize-space(following-sibling::*[$fs1]/@FieldName)" /><xsl:text>"</xsl:text>
   <xsl:choose>
     <xsl:when test="following-sibling::*[$fs-number][@FieldName != 'User Login ID']">
       <xsl:call-template name="column-name">
         <xsl:with-param name="fs1" select="$fs-number" />
       </xsl:call-template>
     </xsl:when>
     <xsl:otherwise><xsl:text>)</xsl:text></xsl:otherwise>
   </xsl:choose>
 </xsl:template>

 <xsl:template name="column-value">
   <xsl:param name="fs1" />
   <xsl:variable name="fs-number" select="$fs1 + 1" />
<xsl:text>,"</xsl:text><xsl:value-of select="normalize-space(following-sibling::*[$fs1])" /><xsl:text>"</xsl:text>
   <xsl:choose>
     <xsl:when test="following-sibling::*[$fs-number][@FieldName != 'User Login ID']">
       <xsl:call-template name="column-value">
         <xsl:with-param name="fs1" select="$fs-number" />
       </xsl:call-template>
     </xsl:when>
     <xsl:otherwise><xsl:text>);</xsl:text></xsl:otherwise>
   </xsl:choose>
 </xsl:template>

</xsl:stylesheet>
--
Charles Knell
cknell@xxxxxxxxxx - email



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



Current Thread