[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

Subject: Re: Malformed (??) XML and XML 2 SQL XSLT transformation
From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx>
Date: Fri, 14 Nov 2003 15:32:58 +0000
xsl eliminate whitespaces function
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('&quot;', @FieldName, '&quot;')" />
    <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

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.