473,624 Members | 2,186 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

xml + xslt convert to rtf problem

Hi there,
I create an XML file from a dataset like this:

System.IO.Strea mWriter xmlSW = new System.IO.Strea mWriter(FILENAM E);
dsUserData1.Wri teXml(xmlSW, XmlWriteMode.Wr iteSchema);
xmlSW.Close();

Which gives me this XML file:

<NewDataSet>
<tblUserData>
<User_ID>Admini strator</User_ID>
<User_Name>So me Name</User_Name>
<User_Position> Analyst Programmer</User_Position>
<User_Departmen t>Forensic & Special</User_Department >
<User_Phone>0 3 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\wwwr oot\PersonalDat a\xml\"+strTmp+ ".xml";
XslTransform xslt = new XslTransform();
xslt.Load(FILEN AME);
XPathDocument xpathdocument = new XPathDocument(f ilename);

XmlTextWriter writer = new
XmlTextWriter(@ "\Inetpub\wwwro ot\PersonalData \xml\"+strTmp+" .rtf",
System.Text.Enc oding.Default);

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

This is the according XSLT file:

<?xml version="1.0" encoding="UTF-8" ?>
<xsl:styleshe et xmlns:xsl="http ://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:output method="text" />
<xsl:template match="/">
<xsl:text>{\rtf 1</xsl:text>
<xsl:for-each select="NewData Set/tblUserData">
<xsl:text>\b </xsl:text>
<xsl:value-of select="User_Na me"/>
<xsl:text>\b0 </xsl:text>
<xsl:text>\pa r </xsl:text>
<xsl:value-of select="User_Po sition"/>
<xsl:text>\pa r </xsl:text>
<xsl:value-of select="User_De partment"/>
<xsl:text>\pa r </xsl:text>
<xsl:value-of select="User_Ph one"/>
<xsl:text>\pa r </xsl:text>
<xsl:value-of select="User_Fa x"/>
</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 5276
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***@discussi ons.microsoft.c om> wrote in message
news:B5******** *************** ***********@mic rosoft.com...
Hi there,
I create an XML file from a dataset like this:

System.IO.Strea mWriter xmlSW = new System.IO.Strea mWriter(FILENAM E);
dsUserData1.Wri teXml(xmlSW, XmlWriteMode.Wr iteSchema);
xmlSW.Close();

Which gives me this XML file:

<NewDataSet>
<tblUserData>
<User_ID>Admini strator</User_ID>
<User_Name>So me Name</User_Name>
<User_Position> Analyst Programmer</User_Position>
<User_Departmen t>Forensic & Special</User_Department >
<User_Phone>0 3 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\wwwr oot\PersonalDat a\xml\"+strTmp+ ".xml";
XslTransform xslt = new XslTransform();
xslt.Load(FILEN AME);
XPathDocument xpathdocument = new XPathDocument(f ilename);

XmlTextWriter writer = new
XmlTextWriter(@ "\Inetpub\wwwro ot\PersonalData \xml\"+strTmp+" .rtf",
System.Text.Enc oding.Default);

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

This is the according XSLT file:

<?xml version="1.0" encoding="UTF-8" ?>
<xsl:styleshe et xmlns:xsl="http ://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:output method="text" />
<xsl:template match="/">
<xsl:text>{\rtf 1</xsl:text>
<xsl:for-each select="NewData Set/tblUserData">
<xsl:text>\b </xsl:text>
<xsl:value-of select="User_Na me"/>
<xsl:text>\b0 </xsl:text>
<xsl:text>\pa r </xsl:text>
<xsl:value-of select="User_Po sition"/>
<xsl:text>\pa r </xsl:text>
<xsl:value-of select="User_De partment"/>
<xsl:text>\pa r </xsl:text>
<xsl:value-of select="User_Ph one"/>
<xsl:text>\pa r </xsl:text>
<xsl:value-of select="User_Fa x"/>
</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\wwwro ot\PersonalData \xml\"+strTmp+" .rtf",
System.Text.Enc oding.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
3397
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 happening when I put my XML files and the .xsl files on my ISP's system for my home page. If I try to open the XML files in Netscape 7.0 on my own machine (ie, not on the ISP's system), the pages convert file and the result is displayed in HTML.
4
1219
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 empty xmlns attribute: <Meldekorttype xmlns="http://myhost.com/mk_print_meldekort.xsd"> <tag1>Value1</tag1> <tag2>Value2</tag2> </Meldekorttype>
1
3101
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 Transformer convert that via XSLT to valid XSL-FO. So I define a SAXReader which fires the SAX Events for the Java Object. This works fine and the Transformation to PDF is ok. However, I have one object which contains an XHTML String and the tags
3
2249
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 web pages formatted as a matrix. It is not a simple matrix, since the number of row heading cells can vary, but the data cells must be aligned by date (so the heading cells will not be uniformly sized). example of typical rows: 3 heading...
2
2752
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); xmlSW.Close(); Which gives me this XML file: <NewDataSet>
4
1922
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 8 8 8 8 8 8 8 8 8 9 9 9 9 6 7 7 7 8 8 8 8 9 9 9
12
11578
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 don't want to have to use some external program or script to parse the csv first if possible
2
8906
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 BuildVersion="1,5,0815,0 " CountryName="Afghanistan" > <Language locale="English">
0
1869
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> <NoName> <AggregatedPosition> <PositionReference>549</PositionReference>
0
8173
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8679
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8335
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8475
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7159
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5563
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4174
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2606
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1785
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.