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
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/
> 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?
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.
<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.