?
Solved

xml + xslt convert to rtf problem

Posted on 2005-03-10
7
Medium Priority
?
682 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
7 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Suggested Courses

752 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