XML Editor
Sign up for a WebBoard account Sign Up Keyword Search Search More Options... Options
Chat Rooms Chat Help Help News News Log in to WebBoard Log in Not Logged in
Show tree view Topic
Topic Page 1 2 3 4 5 6 7 8 9 Go to previous topicPrev TopicGo to next topicNext Topic
Postnext
alec eiffelSubject: extra carriage returns in "csv" output from xslt
Author: alec eiffel
Date: 09 Mar 2009 11:46 AM
Hi there,

I'm using this XSL to process an XML file that I eventually want in CSV.

<?xml version='1.0' ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output indent="no" method="text"/>
<xsl:template match="nC">
<xsl:text disable-output-escaping="yes">"</xsl:text>
<xsl:value-of select="normalize-space(id)"/>
<xsl:text disable-output-escaping="yes">"</xsl:text>
<xsl:text disable-output-escaping="yes">,</xsl:text>
<xsl:text disable-output-escaping="yes">"</xsl:text>
<xsl:value-of select="normalize-space(name)"/>
<xsl:text disable-output-escaping="yes">"</xsl:text>
</xsl:template>
</xsl:stylesheet>

And I am getting this output:



"01","basic"

"02","task1 bundle"


"03","task2 bundle"


"04","task1 family"

Where the carriage returns between lines are extra, and need to be suppressed. The spaces at the beginning of lines need to be suppressed in the CSV output, which I want to look like:

"01","basic"
"02","task1 bundle"
"03","task2 bundle"
"04","task1 family"


Can anyone see what I am doing wrong here? Thanks for the input!!

alec

Postnext
Tony LavinioSubject: extra carriage returns in
Author: Tony Lavinio
Date: 09 Mar 2009 03:44 PM
The default template rules are matching whitespace in your document.
(Also, using disable-output-escaping is almost always indicative of an
error present or waiting to happen. Your best bet is to simply pretend
it doesn't exist.)
((And since you didn't post your input document, this is a guess...))

<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output indent="no" method="text"/>
<xsl:template match="/">
<xsl:apply-templates select="//nC"/>
</xsl:template>
<xsl:template match="nC">
<xsl:text>"</xsl:text>
<xsl:value-of select="normalize-space(id)"/>
<xsl:text>","</xsl:text>
<xsl:value-of select="normalize-space(name)"/>
<xsl:text>"&#xD;&#xA;</xsl:text>
</xsl:template>
</xsl:stylesheet>

Posttop
alec eiffelSubject: extra carriage returns in
Author: alec eiffel
Date: 09 Mar 2009 05:23 PM
Thank you Tony, very much. You must have guessed correctly, because when I added the additional statements

<xsl:template match="/">
<xsl:apply-templates select="//nC"/>
</xsl:template>

then all worked as expected.

 
Topic Page 1 2 3 4 5 6 7 8 9 Go to previous topicPrev TopicGo to next topicNext Topic
Download A Free Trial of Stylus Studio 6 XML Professional Edition Today! Powered by Stylus Studio, the world's leading XML IDE for XML, XSLT, XQuery, XML Schema, DTD, XPath, WSDL, XHTML, SQL/XML, and XML Mapping!  
go

Log In Options

Site Map | Privacy Policy | Terms of Use | Trademarks
Stylus Scoop XML Newsletter:
W3C Member
Stylus Studio® and DataDirect XQuery ™are from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2016 All Rights Reserved.