472,985 Members | 2,894 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,985 software developers and data experts.

xml + xslt convert to rtf problem

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
Nov 12 '05 #1
2 5209
Chris,

Your XML file is not a well formed XML file.
A well fromed XML file should not contains & but &amp;.
The xslt.Transform() "smart" enough to convert &amp; to & if the
<xsl:output method="text" /> was used.
I ran your example with &amp; in the Xml file and here is what I got:
{\rtf1\b Some Name\b0 \par Analyst Programmer\par Forensic & Special\par 03
9632 0872\par 03 9632 0875}

So you might want to check your output Xml file and make sure that it was
written correctly.

Duy
CSDP/MCSD

"chris" <ch***@discussions.microsoft.com> wrote in message
news:B5**********************************@microsof t.com...
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

Nov 12 '05 #2
chris wrote:
Now I convert the XML to an rtf file with the help of a xslt file:
Nope, you are converting it to XML file, because you are transforming to
XmlTextWriter.
XmlTextWriter writer = new
XmlTextWriter(@"\Inetpub\wwwroot\PersonalData\xml\ "+strTmp+".rtf",
System.Text.Encoding.Default);

xslt.Transform(xpathdocument, null, writer, null);
writer.Close(); <xsl:output method="text" />


This is ignored when transformtion is done to XmlWriter or XmlReader.
Transform to TextWriter or Stream instead.

--
Oleg Tkachenko [XML MVP, MCP]
http://blog.tkachenko.com
Nov 12 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: nanookfan | last post by:
Hi all, I'm having a bizarre problem converting XML files to HTML using an XSLT. The problem is only occuring in my Netscape 7.0 browser. What makes it more bizarre is that it is only...
4
by: Trygve | last post by:
I'm trying to convert a XML-document using XSLT. Depending on the source file (the XML-document) the conversion is either correct or incorrect. If the first tag in the document contains an non...
1
by: Jens Mueller | last post by:
Hi there, this is a Java-XML Question, so I am not sure whether this is the right place, haven't found anything better .... I try to convert a Java object to XML via SAX and let the FOP...
3
by: Jack Fox | last post by:
I've never had the need to work with XML, but I believe I now have an appropriate application. I have time-series data in objects organized as a tree that I want an ASP.NET program to write out to...
2
by: chris | last post by:
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);...
4
by: shaun roe | last post by:
I should like to count the frequency of strings embedded in a longer string, space separated. Specifically, I have: <phiModule> 5 5 5 5 6 6 6 6 7 7 7 7 8 8 8 8 8 5 5 5 6 6 6 7 7 7 7 7 7 7 7...
12
by: Chris | last post by:
Hi, Just wondering if anyone out there knows if it is possible to convert a CSV to xml using XSLT? I've seen a lot of examples of xml to CSV, but is it possible to go back the other way? I...
2
by: Ch Pravin | last post by:
Hi All: I am having the following xml which i need to convert to excel using xslt. Please help me out. Afghanistan.xml <?xml version="1.0" encoding="utf-16"?> <Languages...
0
by: vikasthukral17 | last post by:
Hello Friends i want to convert xml shown under into excel file,xml is as <?xml version="1.0" standalone="yes"?> <?xml-stylesheet type="text/xsl" href="AggrPositions.xsl"?> <DataOut> ...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.