Removing line breaks when using XSLT to convert XML to text
Posted: Wed Jan 14, 2009 1:04 pm
I am using Oxygen Author and trying to establish how to control the presence or absence of line breaks where I want them in a text file generated by applying an XSLT transformation to an XML file.
The XML is as follows:
I want both this and the following (which is equivalent, without the linebreaks) to produce the same result from any transformation.
Can anyone help? I've tried the following stylesheet but it produces different results for the two inputs.
How can I control whether I get:
or
or
regardless of whether there are linebreaks or spaces in the input XML?
The XML is as follows:
Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE l1 SYSTEM "Simple.dtd">
<?xml-stylesheet type="text/xsl" href="Simple2.xsl"?>
<l1><l2><l3>1a</l3><l3>1b</l3><l3>1c</l3>
</l2>
<l2>
<l3>2a</l3><l3>2b</l3><l3>2c</l3>
</l2>
<l2>
<l3>3a</l3>
<l3>3b</l3>
<l3>3c</l3>
</l2>
</l1>
Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE l1 SYSTEM "Simple.dtd">
<?xml-stylesheet type="text/xsl" href="Simple2.xsl"?>
<l1><l2><l3>1a</l3><l3>1b</l3><l3>1c</l3></l2><l2><l3>2a</l3><l3>2b</l3><l3>2c</l3></l2><l2><l3>3a</l3><l3>3b</l3><l3>3c</l3></l2></l1>
Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="text" encoding="utf-8" />
<xsl:template match="/"><xsl:apply-templates/></xsl:template><xsl:template match="l1"><xsl:apply-templates/></xsl:template><xsl:template match="l2"><xsl:apply-templates/></xsl:template><xsl:template match="l3"><xsl:value-of select="."/></xsl:template>
</xsl:stylesheet>
Code: Select all
1a1b1c2a2b2c3a3b3c
Code: Select all
1a1b1c
2a2b2c
3a3b3c
Code: Select all
1a
1b
1c
2a
2b
2c
3a
3b
3c