473,386 Members | 1,706 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

How to output numerical entity encodings with the XslTransform class?

I am using the XslTransform class in C#.net to output XML files that include
non-ascii Unicode characters such as the Greek capital letter theta U+0398.
I can easily outout the data as serialized UTF-8 by using the default
encoding of UTF-8; however, my customer wants any non-ascii characters
output as numerically-entity encoded characters, e.g. Θ (where 920 is
the decimal equivalent for hexadecimal 398). If I use the Saxon processor
or MSXSL, and the xsl transform has the output type set to us-ascii as
follows:

<xsl:output method="xml" encoding="us-ascii" indent="no" />

then all non-ascii characters are automatically output as numerically-entity
encoded characters. However, if I use the XsltTransform class outputting to
a streamwriter with an encoding type of ASCII, then no entity encoding takes
place - in fact the character is replaced with a question mark. Can anyone
tell me how to configure the properties of the transform to output
numerically-entity encoded characters for all non-ascii characters?

Thank you,

Tim

Nov 12 '05 #1
2 1995
Tim Meagher wrote:
I am using the XslTransform class in C#.net to output XML files that include
non-ascii Unicode characters such as the Greek capital letter theta U+0398.
I can easily outout the data as serialized UTF-8 by using the default
encoding of UTF-8; however, my customer wants any non-ascii characters
output as numerically-entity encoded characters, e.g. Θ (where 920 is
the decimal equivalent for hexadecimal 398).

XslTransform doesn't support that. Here is one of possible solutions:
http://www.tkachenko.com/blog/archives/000266.html

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

Thanks for the tip. I used it as a basis for overriding the
StreamWriter write method to accomplish the same thing. Here's what I
ended up with:

public sealed class ASCIIStreamWriter : StreamWriter
{
//Constructors - add more as needed
public ASCIIStreamWriter(string url, bool append, Encoding encoding) :
base(url, append, encoding) {}

public override void Write(string text)
{
StringBuilder sb = new StringBuilder(text.Length);
foreach (char c in text)
{
if (c > 0x0080)
{
sb.Append("&#");
sb.Append((int)c);
sb.Append(';');
}
else
{
sb.Append(c);
}
}
base.Write(sb.ToString());
}
}

Regards,

Tim


*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 12 '05 #3

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

Similar topics

4
by: Chris Curvey | last post by:
I'm writing an XMLRPC server, which is receiving a request (from a non-Python client) that looks like this (formatted for legibility): <?xml version="1.0"?> <methodCall>...
81
by: Jonas Smithson | last post by:
I recently read the claim somewhere that numerical entities (such as —) have a speed advantage over the equivalent named entities (such as &mdash;) because the numerical entity requires just a...
2
by: John Meyer | last post by:
I have an application where I create an xml fragment using an XslTransform object. However, if I use the following output method, <xsl:output method="xml" version="1.0" encoding="UTF-8"...
1
by: Tim Menninger | last post by:
When I use the XslTransform.Transform method to write to the HttpRequest.OutputStream The first byte of the output is always an invalid character, looks like an ascii zero or some other...
3
by: Joseph A Romeo | last post by:
I have written an XSLT transformation on an ASP.NET page. The resulting HTML is primarily a table of links. I have found that when the resulting HTML is less than or equal to 16040 bytes, the...
2
by: Lionel Fourquaux | last post by:
In .Net 1.1, System.Xml.Xsl.XslTransform cannot output directly a document in an encoding that cannot represent all the characters used (e.g. write in us-ascii for compatibility, and convert all...
3
by: Fredy Muñoz [MCP] | last post by:
Hello there! I have a couple of questions about generating HTML using an XSLT Stylesheet. I use the System.Xml and System.Xml.Xsl namespaces and a XslTransform object to make the...
0
by: Tim Meagher | last post by:
I am using the XslTransform class in C#.net to output XML files that include non-ascii Unicode characters such as the Greek capital letter theta U+0398. I can easily outout the data as serialized...
18
by: Terry Holland | last post by:
I have an asp.net (1.1) application that connects to a SQL server 2000 db. I have a stored procedure in my db that out puts data in xml format. What I need to be able to do is display that xml...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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,...

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.