XSLT - XML to CSV - template vs. for-each - remove whitespace

Mannafe

New Member
(1) Why does Option1 (Template) produce whitespace (mainly btw rec1 & 5) whereas Option2 (ForEach) doesn't?
(2) If possible, how do I code Option1 to remove the resulting whitespace?
Assumptions: use of XSLT v1., XMLPad/Stylus for testing, MSXML4.
Working on processing larger, more complex XML input files (mix of elements/attributes) with multiple 'type' selection criteria to create multiple TSV output files. A number of references seem to indicate using Templates as the preferable method. Using match currently pushes too much whitespace to the message queue. XML:\[code\]<main> <event> <event_type>Bike</event_type> <date>2012-02-05</date> </event> <event> <event_type>Run</event_type> <date>2012-02-06</date> </event> <event> <event_type>Swim</event_type> <date>2012-02-07</date> </event> <event> <event_type>Run</event_type> <date>2012-02-08</date> </event> <event> <event_type>Bike</event_type> <date>2012-02-09</date> </event></main>\[/code\]XSL:\[code\]<?xml version="1.0" encoding="utf-8"?><xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="text"/> <xsl:variable name="tab" select="' '" /><xsl:template match="@*|text()"/><xsl:template match="/"><xsl:text/>event<xsl:value-of select="$tab"/><xsl:text/>date<xsl:value-of select="$tab"/><xsl:apply-templates/></xsl:template><!-- OPTION1 --><xsl:template match="event[event_type='Bike']"><xsl:text></xsl:text><xsl:value-of select="event_type"/><xsl:value-of select="$tab"/><xsl:value-of select="date"/></xsl:template><!-- OPTION2 --><!--<xsl:template match="@*|node()"><xsl:for-each select="event[event_type='Bike']"><xsl:text></xsl:text><xsl:value-of select="event_type"/><xsl:value-of select="$tab"/><xsl:value-of select="date"/></xsl:for-each></xsl:template>--></xsl:stylesheet>\[/code\]Output - Opt1 Template (can't post pics yet, ... are whitespace)event...date......
Bike....2012-02-05............
Bike....2012-02-09.
Output - Opt2 ForEachevent...date.....
Bike....2012-02-05
Bike....2012-02-09
 
Back
Top