Breaking line in method="text" mode

Here should go questions about transforming XML with XSLT and FOP.
TPP
Posts: 5
Joined: Fri Mar 24, 2006 6:32 pm

Breaking line in method="text" mode

Post by TPP »

How do you break line in text output:

XML:


<?xml version="1.0" standalone="yes"?>
<N1>
<N11>
<N111>1</N111>
<N222>2</N222>
<N333>3</N333>
</N11>
<N22>
<N111>6</N111>
<N222>7</N222>
<N333>8</N333>
</N22>
</N1>



XSLT:

<?xml version="1.0" encoding="windows-1250"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:output method="text" omit-xml-declaration="yes" encoding="ascii" />
<xsl:preserve-space elements="*"/>


<xsl:template match="/">
<xsl:value-of select="N1/N11/N111"/>
<xsl:value-of select="N1/N11/N222"/>
<xsl:value-of select="N1/N11/N333"/>

<xsl:value-of select="N1/N22/N111"/>
<xsl:value-of select="N1/N22/N222"/>
<xsl:value-of select="N1/N22/N333"/>
</xsl:template>

</xsl:stylesheet>



I get:

123456

...ok, but how do you break line after 3 to get:

123
456

Thanks for help, Peter.
Radu
Posts: 9048
Joined: Fri Jul 09, 2004 5:18 pm

Post by Radu »

Hi, Peter

Here's a way:

Code: Select all

<?xml version="1.0" encoding="windows-1250"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:output method="text" omit-xml-declaration="yes" encoding="ascii"/>
<xsl:preserve-space elements="*"/>


<xsl:template match="/">
<xsl:value-of select="N1/N11/N111"/>
<xsl:value-of select="N1/N11/N222"/>
<xsl:value-of select="N1/N11/N333"/>
<xsl:text>
</xsl:text>
<xsl:value-of select="N1/N22/N111"/>
<xsl:value-of select="N1/N22/N222"/>
<xsl:value-of select="N1/N22/N333"/>
</xsl:template>

</xsl:stylesheet>
Notice the added xsl:text tag which contains inside exactly one line break.

Regards, Radu
Post Reply