By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,671 Members | 1,387 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,671 IT Pros & Developers. It's quick & easy.

xml + xslt convert to rtf problem

P: n/a
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 16 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
"chris" <ch***@discussions.microsoft.com> wrote in message news:14**********************************@microsof t.com...
<User_Department>Forensic & Special</User_Department> : : <xsl:value-of select="User_Department"/> : : Forensic &amp; Special


a.k.a., output escaping. Solution is to change the xsl:value-of in your stylesheet
to,

<xsl:value-of selec="User_Department" disable-output-escaping="yes" />

If there's a chance of '&' or '<' appearing in any of your XML input document's
other elements than you'd also want to disable-output-escaping on their xsl:value-of,
too.
Derek Harmon
Nov 16 '05 #2

P: n/a
Thank you. Unfortunately it doesn't work. The problem must be somewhere else.

Cheers

"Derek Harmon" wrote:
"chris" <ch***@discussions.microsoft.com> wrote in message news:14**********************************@microsof t.com...
<User_Department>Forensic & Special</User_Department>

: :
<xsl:value-of select="User_Department"/>

: :
Forensic & Special


a.k.a., output escaping. Solution is to change the xsl:value-of in your stylesheet
to,

<xsl:value-of selec="User_Department" disable-output-escaping="yes" />

If there's a chance of '&' or '<' appearing in any of your XML input document's
other elements than you'd also want to disable-output-escaping on their xsl:value-of,
too.
Derek Harmon

Nov 16 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.