?
Solved

xml + xslt convert to rtf problem

Posted on 2005-03-10
7
Medium Priority
?
696 Views
Last Modified: 2008-02-01
Hi there,
I create an XML file from a dataset like this:

System.IO.StreamWriter xmlSW = new System.IO.StreamWriter(FILENAME);
dsUserData1.WriteXml(xmlSW, XmlWriteMode.WriteSchema);
xmlSW.Close();

Which gives me this XML file:

<NewDataSet>
  <tblUserData>
    <User_ID>Administrator</User_ID>
    <User_Name>Some Name</User_Name>
    <User_Position>Analyst Programmer</User_Position>
    <User_Department>Forensic & Special</User_Department>
    <User_Phone>03 9632 0872</User_Phone>
    <User_Fax>03 9632 0875</User_Fax>
  </tblUserData>
</NewDataSet>

Now I convert the XML to an rtf file with the help of a xslt file:

string filename = @"\Inetpub\wwwroot\PersonalData\xml\"+strTmp+".xml";
XslTransform xslt = new XslTransform();
xslt.Load(FILENAME);
XPathDocument xpathdocument = new XPathDocument(filename);

XmlTextWriter writer = new
XmlTextWriter(@"\Inetpub\wwwroot\PersonalData\xml\"+strTmp+".rtf",
System.Text.Encoding.Default);

xslt.Transform(xpathdocument, null, writer, null);
writer.Close();

This is the according XSLT file:

<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
      <xsl:output method="text" />
      <xsl:template match="/">
      <xsl:text>{\rtf1</xsl:text>
      <xsl:for-each select="NewDataSet/tblUserData">
      <xsl:text>\b </xsl:text>
      <xsl:value-of select="User_Name"/>
      <xsl:text>\b0 </xsl:text>
      <xsl:text>\par </xsl:text>
      <xsl:value-of select="User_Position"/>
      <xsl:text>\par </xsl:text>
      <xsl:value-of select="User_Department"/>
      <xsl:text>\par </xsl:text>
      <xsl:value-of select="User_Phone"/>
      <xsl:text>\par </xsl:text>
      <xsl:value-of select="User_Fax"/>
      </xsl:for-each>
      <xsl:text>}</xsl:text>
</xsl:template>
</xsl:stylesheet>

But the problem is that the & is not converted into &.

Some Name
Analyst Programmer
Forensic &amp; Special
03 9632 0872
03 9632 0875

What could be the problem here? I tried using Schema as well, still the same
problem. Please help

Thank you

Chris
0
Comment
Question by:ccoe1
  • 3
  • 2
6 Comments
 
LVL 18

Expert Comment

by:testn
ID: 13513264
try this...

<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
     <xsl:output method="text" />
     <xsl:template match="/">
     <xsl:text>{\rtf1</xsl:text>
     <xsl:for-each select="NewDataSet/tblUserData">
     <xsl:text>\b </xsl:text>
     <xsl:value-of disable-output-escaping="yes" select="User_Name"/>
     <xsl:text>\b0 </xsl:text>
     <xsl:text>\par </xsl:text>
     <xsl:value-of disable-output-escaping="yes" select="User_Position"/>
     <xsl:text>\par </xsl:text>
     <xsl:value-of disable-output-escaping="yes" select="User_Department"/>
     <xsl:text>\par </xsl:text>
     <xsl:value-of disable-output-escaping="yes" select="User_Phone"/>
     <xsl:text>\par </xsl:text>
     <xsl:value-of disable-output-escaping="yes" select="User_Fax"/>
     </xsl:for-each>
     <xsl:text>}</xsl:text>
</xsl:template>
</xsl:stylesheet>
0
 

Author Comment

by:ccoe1
ID: 13513730
Thank you. Unfortunately it doesn't work. The problem must be somewhere else.

Cheers
0
 
LVL 18

Expert Comment

by:testn
ID: 13513763
btw your xml is not valid.... may be that's the case....

& should be encoded as &amp; in xml file
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

Author Comment

by:ccoe1
ID: 13514008
the xml file contains the &amp; as it should.

Chris
0
 

Author Comment

by:ccoe1
ID: 13531471
I solved it my self. There are no problems with any of the files nor the code. It is a bug in the .Net Framework itself. I used now Response and it works like a dream:

XmlDataDocument xmlDoc2 = new XmlDataDocument(ds);        
XslTransform xslTran = new XslTransform();
xslTran.Load(@"\mySchema.xslt");
Response.ContentType = "application/msword";
Response.Charset = "";
Response.ContentEncoding = System.Text.Encoding.Default;
Response.AddHeader("Content-Disposition", "inline;filename="+userName+".rtf");
xslTran.Transform(xmlDoc2, null, Response.Output, null);

Thanks for your help guys

Chris
0
 

Accepted Solution

by:
OzzMod earned 0 total points
ID: 13573742
Closed, 500 points refunded.
OzzMod
Community Support Moderator (Graveyard shift)
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
Suggested Courses
Course of the Month9 days, 20 hours left to enroll

569 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question