|
Subject: Re: [xsl] Malformed (??) XML and XML 2 SQL XSLT transformation From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx> Date: Fri, 14 Nov 2003 15:32:58 +0000 |
Hi Charles,
> The lines are longer than I would like, but were necessary in order
> to eliminate unwanted whitespace in the output.
Use <xsl:text> around text in order to make the stylesheet look nice
without passing whitespace through into the output. For example,
rather than:
> <xsl:template match="Orders" mode="columns">INSERT INTO orders(<xsl:for-each select="Customer/Template/Fields">"<xsl:value-of select="@FieldName" />"<xsl:if test="position() != last()">,</xsl:if></xsl:for-each>)</xsl:template>
use:
<xsl:template match="Orders" mode="columns">
<xsl:text>INSERT INTO orders(</xsl:text>
<xsl:for-each select="Customer/Template/Fields">
<xsl:text>"</xsl:text>
<xsl:value-of select="@FieldName" />
<xsl:text>"</xsl:text>
<xsl:if test="position() != last()">,</xsl:if>
</xsl:for-each>
<xsl:text>)</xsl:text>
</xsl:template>
This works because whitespace-only text nodes in the tree generated
from the stylesheet document automatically get stripped, unless they
appear within <xsl:text> elements. So <xsl:text> effectively delimits
the text that you're interested in from the whitespace that you don't
want.
You can also use the concat() function in an <xsl:value-of> to reduce
the verbosity and help manage whitespace:
<xsl:template match="Orders" mode="columns">
<xsl:text>INSERT INTO orders(</xsl:text>
<xsl:for-each select="Customer/Template/Fields">
<xsl:value-of select="concat('"', @FieldName, '"')" />
<xsl:if test="position() != last()">,</xsl:if>
</xsl:for-each>
<xsl:text>)</xsl:text>
</xsl:template>
Cheers,
Jeni
---
Jeni Tennison
http://www.jenitennison.com/
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
| Current Thread |
|---|
|
| <- Previous | Index | Next -> |
|---|---|---|
| RE: [xsl] Malformed (??) XML and XM, Andreas L. Delmelle | Thread | RE: RE: [xsl] Malformed (??) XML an, cknell |
| RE: [xsl] Can anyone point me in th, Andreas L. Delmelle | Date | RE: RE: [xsl] Malformed (??) XML an, cknell |
| Month |