|
[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: Malformed (??) XML and XML 2 SQL XSLT transformati
Guillaume LECERF wrote:
Well, the structure is not too bad as it is. One somewhat generic approach
is to select the Fields with the same as the first field and then select the
fields between them in an inner for-each. Unfortunately, I can't remember the
most elegant way to do the latter, but it is surely in the list archive:
<xsl:template match="Template">
<xsl:variable name="first-field-name" select="Fields[1]/@FieldName"/>
<xsl:for-each select="Fields[FieldName=$first-field-name]">
<xsl:variable name="this-id" select="generate-id()"/>
<xsl:variable name="fields" select="following-sibling::Fields
[generate-id(previous-sibling::Fields[1])=$this-id]"/>
<xsl:text>INSERT INTO orders(</xsl:text>
<xsl:for-each select="$fields">
<xsl:text>"</xsl:text>
<xsl:value-of select="@FieldName"/>
<xsl:text>"</xsl:text>
<xsl:if test="position()!=last()">
<xsl:text>,</xsl:text>
</xsl:if>
</xsl:for-each>
<xsl:text>)
values(</xsl:text>
<xsl:for-each select="$fields">
<xsl:text>"</xsl:text>
<xsl:value-of select="FieldValue"/>
<xsl:text>"</xsl:text>
<xsl:if test="position()!=last()">
<xsl:text>,</xsl:text>
</xsl:if>
</xsl:for-each>
<xsl:text>);
</xsl:text>
</xsl:for-each>
</xsl:template>
Beware: untested.J.Pietschmann XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|

Cart








