xml + xslt convert to rtf problem

G

Guest

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:blush:utput 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
 
D

Derek Harmon

chris said:
<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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top