XSL change to a new line

XSL (Extensible Stylesheet Language) is used to refer to a family of languages used to transform and render XML documents.

For me, I have encounter a problem when I wrote a xsl, all the output is in one line.

xsl file before :

<?xml version=”1.0″ encoding=”UTF-8″?>
<xsl:stylesheet version=”1.0″ xmlns:xsl=”http://www.w3.org/1999/XSL/Transform”&gt;
<xsl:output method=”text” version=”1.0″ encoding=”UTF-8″ omit-xml-declaration=”no” indent=”yes” />
<xsl:template match=”/”>
<xsl:apply-templates select=”path”/>
</xsl:template>
<xsl:template match=”path”>
<xsl:value-of select=”str[@name=’id’]” />,<xsl:value-of select=”str[@name=’name’]” />
</xsl:template>
</xsl:stylesheet>

output before :

1,AAA2,BBB3,CCC

—————————–

So I add a little “\n” after each line. In xsl, it is <xsl:text> </xsl:text>.

xsl file after :

<?xml version=”1.0″ encoding=”UTF-8″?>
<xsl:stylesheet version=”1.0″ xmlns:xsl=”http://www.w3.org/1999/XSL/Transform”&gt;

<xsl:output method=”text” version=”1.0″ encoding=”UTF-8″ omit-xml-declaration=”no” indent=”yes” />

<xsl:template match=”/”>
<xsl:apply-templates select=”response/result/doc”/>
</xsl:template>

<xsl:template match=”response/result/doc”>
<xsl:value-of select=”str[@name=’id’]” />,<xsl:value-of select=”str[@name=’fulltext’]” /><xsl:text> </xsl:text>
</xsl:template>
</xsl:stylesheet>

output after :

1,AAA

2,BBB

3,CCC

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s