Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

newLine issue when using XSLCompiledTransform.Transform()

243 views
Skip to first unread message

Zest4Quest

unread,
May 13, 2009, 4:43:02 PM5/13/09
to
Hi,
I have an xml in the following format
<?xml version="1.0" encoding="utf-16"?><Assessment
xmlns:i="http://www.w3.org/2001/XMLSchema-instance" >
<ObGyn>
<OBGYNNotes>a
b
c
d
e
</OBGYNNotes>
</ObGyn>
</Assessment>

The characters in "abcde" all are in seperate lines which is picked up from
the UI.

Now when i transform this xml to an RTF format the "abcde" instead of
retaining the newline effect comes out as "abcde" as if its one word. The
code that i am using to do the conversion is given below. The sXML holds the
above xml.

XslCompiledTransform xslTransform = new XslCompiledTransform();
xslTransform.Load(xSLTFileName);

XsltArgumentList xslArg = new XsltArgumentList();
xslArg.AddParam("PresentTime", "", PresentTime);

xslTransform.Transform(new XPathDocument(new
StringReader(sXML)), xslArg, result);

return result.ToString();

The header of the XSLt used is also given below.
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxsl="urn:schemas-microsoft-com:xslt"
exclude-result-prefixes="msxsl"
xmlns:ms="urn:schemas-microsoft-com:xslt"

xmlns:dt="urn:schemas-microsoft-com:datatypes">
<xsl:param name="Signature"/>
<xsl:param name="PresentTime"/>
<xsl:param name="IsAdult"/>
<xsl:output method="text" indent="yes"/>

<xsl:template match="/">
<xsl:text>{\rtf1{\fonttbl{\f0\fnil\fcharset0
Arial;}}\viewkind4\uc1\pard\lang1033\fs18</xsl:text>

Any help would be very much appreciated...
Thanks


Martin Honnen

unread,
May 14, 2009, 7:47:29 AM5/14/09
to
Zest4Quest wrote:
> Hi,
> I have an xml in the following format
> <?xml version="1.0" encoding="utf-16"?><Assessment
> xmlns:i="http://www.w3.org/2001/XMLSchema-instance" >
> <ObGyn>
> <OBGYNNotes>a
> b
> c
> d
> e
> </OBGYNNotes>
> </ObGyn>
> </Assessment>
>
> The characters in "abcde" all are in seperate lines which is picked up from
> the UI.
>
> Now when i transform this xml to an RTF format the "abcde" instead of
> retaining the newline effect comes out as "abcde" as if its one word. The
> code that i am using to do the conversion is given below. The sXML holds the
> above xml.

How are you looking at the transformation result?
I can't reproduce the problem with a simple console application.
The XSLT is as follows:

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxsl="urn:schemas-microsoft-com:xslt"
exclude-result-prefixes="msxsl"
>

<xsl:output method="text" indent="yes"/>

<xsl:template match="/">
<xsl:value-of select="concat('|', Assessment/ObGyn/OBGYNNotes, '|')"/>
</xsl:template>
</xsl:stylesheet>

The console code simply does

string xml = @"<?xml version=""1.0""

encoding=""utf-16""?><Assessment
xmlns:i=""http://www.w3.org/2001/XMLSchema-instance"" >
<ObGyn>
<OBGYNNotes>a
b
c
d
e
</OBGYNNotes>
</ObGyn>

</Assessment>";

XslCompiledTransform proc = new XslCompiledTransform();
proc.Load(@"..\..\XSLTFile1.xslt");
proc.Transform(new XPathDocument(new StringReader(xml)),
null, Console.Out);

the output on the console is

|a
b
c
d
e
|


So I am not sure where the problem comes from.

--

Martin Honnen --- MVP XML
http://msmvps.com/blogs/martin_honnen/

Zest4Quest

unread,
May 14, 2009, 9:01:01 AM5/14/09
to
Hi Martin,
I am showing it in a RichTexBox in a Winforms application by setting its
.Rtf property.
Thanks

Martin Honnen

unread,
May 14, 2009, 9:11:17 AM5/14/09
to
Zest4Quest wrote:

> I am showing it in a RichTexBox in a Winforms application by setting its
> .Rtf property.

Have you checked the
return result.ToString();
result in the debugger, does it contain the line breaks?

Zest4Quest

unread,
May 14, 2009, 10:26:01 AM5/14/09
to
the "result" does not contain any newline info. it shows as "abc" in debugger
.Should i do anything in the xslt to translate all "\r\n" to something else
explicitly?

Martin Honnen

unread,
May 14, 2009, 10:49:58 AM5/14/09
to
Zest4Quest wrote:
> the "result" does not contain any newline info. it shows as "abc" in debugger
> .Should i do anything in the xslt to translate all "\r\n" to something else
> explicitly?

Can you show us the template that processes that 'OBGYNNotes' element?
Or better show us a minimal but complete stylesheet that allows us to
reproduce the problem.

Zest4Quest

unread,
May 14, 2009, 11:02:21 AM5/14/09
to
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxsl="urn:schemas-microsoft-com:xslt"
exclude-result-prefixes="msxsl"
xmlns:ms="urn:schemas-microsoft-com:xslt"
xmlns:dt="urn:schemas-microsoft-com:datatypes">

<xsl:output method="text" indent="yes"/>

<xsl:template match="/">


<xsl:text>{\rtf1{\fonttbl{\f0\fnil\fcharset0
Arial;}}\viewkind4\uc1\pard\lang1033\fs18</xsl:text>

<xsl:for-each select="Assessment/ObGyn">
<xsl:if test ="OBGYNNotes != ''">
<xsl:text> \line \b Additional Information: \b0 </xsl:text>
<xsl:value-of select ="OBGYNNotes"/>
</xsl:if>
</xsl:for-each>
<xsl:text>}</xsl:text>
</xsl:template>
</xsl:stylesheet>

Martin Honnen

unread,
May 14, 2009, 12:00:04 PM5/14/09
to
Zest4Quest wrote:
> <?xml version="1.0" encoding="utf-8"?>
> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
> xmlns:msxsl="urn:schemas-microsoft-com:xslt"
> exclude-result-prefixes="msxsl"
> xmlns:ms="urn:schemas-microsoft-com:xslt"
> xmlns:dt="urn:schemas-microsoft-com:datatypes">
>
> <xsl:output method="text" indent="yes"/>
>
> <xsl:template match="/">
> <xsl:text>{\rtf1{\fonttbl{\f0\fnil\fcharset0
> Arial;}}\viewkind4\uc1\pard\lang1033\fs18</xsl:text>
> <xsl:for-each select="Assessment/ObGyn">
> <xsl:if test ="OBGYNNotes != ''">
> <xsl:text> \line \b Additional Information: \b0 </xsl:text>
> <xsl:value-of select ="OBGYNNotes"/>
> </xsl:if>
> </xsl:for-each>
> <xsl:text>}</xsl:text>
> </xsl:template>
> </xsl:stylesheet>

When I take that stylesheet and use it with Visual Studio 2008 in a .NET
3.5 application with the following code

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Xml;
using System.Xml.Xsl;
using System.Xml.XPath;

namespace ConsoleApplication568
{
class Program
{
static void Main(string[] args)
{


string xml = @"<?xml version=""1.0""
encoding=""utf-16""?><Assessment
xmlns:i=""http://www.w3.org/2001/XMLSchema-instance"" >
<ObGyn>
<OBGYNNotes>a
b
c
d
e
</OBGYNNotes>
</ObGyn>
</Assessment>";

XslCompiledTransform proc = new XslCompiledTransform();

proc.Load(@"..\..\XSLTFile2.xslt");
string result;
using (StringWriter sw = new StringWriter())
{
proc.Transform(new XPathDocument(new
StringReader(xml)), null, sw);
result = sw.ToString();
sw.Close();
}
Console.WriteLine("Result is|{0}|", result);

}
}
}

it outputs

Result is|{\rtf1{\fonttbl{\f0\fnil\fcharset0
Arial;}}\viewkind4\uc1\pard\lang1033\fs18 \line \b Additional
Information: \b0


a
b
c
d
e
}|

to the console so I don't see any missing line breaks.

Zest4Quest

unread,
May 14, 2009, 1:06:03 PM5/14/09
to
Hi Martin,
I assigned the generated text to the .text property of the RTF control and
it shows it in new lines.But when i set the "result" to the .Rtf property of
the RichText it does not..may be this is a RichTextBox control issue...
Thanks a lot for your help...
0 new messages