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
Conferences Close Tree View
+ Stylus Studio Feature Requests (1192)
+ Stylus Studio Technical Forum (14621)
+ Website Feedback (249)
- XSLT Help and Discussion (7625)
-> + How to assign value to a XSLT ... (3)
-> + Select element value based on ... (2)
-> + Version 10 of Saxon? (8)
-> + How to get the value of a node... (5)
-> + Display Xpath using (4)
-> + XSLT to report (2)
-> + xslt help for a noobie (2)
-> + XSL-FO XML to PDF with XSLT (3)
-> + Using XSLT to transform XML to... (4)
-> + XSLT to sort a list alphabetic... (4)
-> + How to Get Colum Values based ... (2)
-> + non persisting predicate filte... (5)
-> + HTML to XSLT (2)
-> + extra carriage returns in "csv... (2)
-> - extra carriage returns in "csv... (3)
-> ->extra carriage returns in...
-> ->extra carriage returns in...
-> - XSLT slicing and orphan contro... (1)
-> + How to delete CDATA using XSL... (15)
-> + Remove only root namespace, bu... (3)
-> + String Parsing (3)
-> + Calling Java method from XSL (3)
-- Previous [361-380] [381-400] [401-420] Next
+ XQuery Help and Discussion (2017)
+ Stylus Studio FAQs (159)
+ Stylus Studio Code Samples & Utilities (364)
+ Stylus Studio Announcements (113)
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.

   
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.