XML, XSL and ASP.NET

G

Guest

Hi folks,

My problem is this...

I am having an issue with whitespace between XML tags that occurs when I
transform the XSL output to the browser via ASP.NET leaving me with
unexpected results.

Read on if you dare.

I have a XML file (datum.xml) that contains numeric values as shown here

<datums>
<datum>18</datum>
<datum>35</datum>
<datum> 87</datum>
</datum>

I have a XSL file that extracts the data from the XML and generates SVG
(Scalable Vector Graphics). SVG is a W3C standard, much like XML, used to
describe graphic images.

The transformation occurs in my ASP.NET file as shown here...

<%@ Page Language="C#" %>
<%@ Import Namespace="System.Xml" %>
<%@ Import Namespace="System.Xml.Xsl" %>
<%@ Import Namespace="System.Xml.XPath" %>

<script runat="server">

void Page_Load(object sender, System.EventArgs e)
{
// Response.AddHeader("Content-Type", "image/svg+xml");
string xmlPath = Request.PhysicalApplicationPath + @"datum.xml";
string xslPath = Request.PhysicalApplicationPath + @"datum.xsl";

XmlReader rdr = XmlReader.Create(xmlPath);
XslCompiledTransform transform = new XslCompiledTransform ();

//Load the XSL stylsheet into the XslCompiledTransform object
transform.Load(xslPath);

transform.Transform(rdr, null, Response.Output);
}
</script>

If the first line in my Page_Load function is commented out, the SVG is
displayed as text in the browser. If I uncomment the same line, I tell the
browser I am outputting SVG and I "expect" this to occur. It does not occur.

So I do a few tests. First I run the web app to view the SVG text displayed
in the browser that is shown here.

<?xml version="1.0" encoding="utf-8" ?>
- <svg height="100" width="100" viewBox="0 0 100 100"
xmlns:svg="http://www.w3.org/2000/svg">
<rect x="10" y="77" width="10" height="23" fill="red" stroke="black" />
<rect x="20" y="6" width="10" height="94" fill="red" stroke="black" />
<rect x="30" y="45" width="10" height="55" fill="red" stroke="black" />
</svg>

Next I copy the text as is and paste it into NotePad and then I save the
file as test1.svg. I then open my IE browser and select File->Open. I click
browse and select test1.svg. I click Ok and see a blank screen.

Finally I copy the same text in NotePad but this time I remove every space
and
CRLF between the tags. I save this file as test2.svg. I open my IE browser
and click File->Open to open test2.svg and I see a barchart which is my
expected result.

What I need to do is find a way to remove the whitespace and CRLF between
the tags in my ASP.NET code.

Any thoughts, ideas are welcome.
- Glenn
 

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

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,011
Latest member
AjaUqq1950

Latest Threads

Top