Page 1 of 1

newline in xml out put

Posted: Fri Sep 18, 2009 10:32 pm
by seshav
Hi,
I am trying to out put the contents of xml file in the form of html table. Data within xml tags displayed as individual rows data.
for example:
<Cd>
<songs>
1. BillieJean
2. Read my heart
3. No where to go
</songs>
<songs>
1. Bad
2. I am sorry
3. Jump on train
</songs>
</Cd>
My xslt outputs the data in the form of html table with
<xsl:for-each select="Cd/songs">
<xsl:value-of select="."/>
</xsl:for-each>
My problem is the output comes as a single line in these rows
(1. BillieJean2. Read my heart3. No where to go). I want these be displayed as individual lines withis the each row of table.
(
1. Bad
2. I am sorry
3. Jump on train
) Just like what I see in xml file.
I tried all sorts <xsl:text>
</xsl:text> and newline characters but I am unable to produce the desired results.
Can any one please suggest what changes I need to do to get the desired results?
Thank you in advance.

Re: newline in xml out put

Posted: Thu Sep 24, 2009 3:03 pm
by sorin_ristache
Hello,

I don't understand how you get the concatenated lines of a songs element in the output. If the text lines of a songs element are separated with a newline in the XML file they are separated in the output of the transformation too because <xsl:value-of select="."/> will copy the content of the songs element without changing it. You can see that with the following two files:

test.xml:

Code: Select all

<Cd>
<songs>
1. BillieJean
2. Read my heart
3. No where to go
</songs>
<songs>
1. Bad
2. I am sorry
3. Jump on train
</songs>
</Cd>
test.xsl:

Code: Select all

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:template match="/">
<xsl:for-each select="Cd/songs">
<xsl:value-of select="."/>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>

Regards,
Sorin

Re: newline in xml out put

Posted: Thu Sep 24, 2009 3:09 pm
by sorin_ristache
That was for text output. If you want to put the content of a songs element in an HTML table you have to parse the text content of each songs element and separate the lines in the output with an element <br />.


Regards,
Sorin