XML Editor
Sign up for a WebBoard account Sign Up Keyword Search Search More Options... Options
Chat Rooms Chat Help Help News News Log in to WebBoard Log in Not Logged in
Show tree view Topic
Topic Page 1 2 3 4 5 6 7 8 9 Go to previous topicPrev TopicGo to next topicNext Topic
Postnext
Glenn MeadowsSubject: xsl:strip-space
Author: Glenn Meadows
Date: 27 Oct 2006 03:47 PM
Hi folks,

I have listed 3 very brief files for discussion purposes. They include an XML file, an XSL file and an ASP.NET file using C#.
I usually upload files but these are small enough to list here.

If you take the XML and XSL files into SS and run them, you will see a graphic image in the output window showing a barchart.

If I run my ASP.NET file that calls both the XSL and XML files, my browser window opens and displays the XML text as output (in this case the text is for SVG (a W3C standard much like XML) shown at the bottom of this post).

I see the text to be formatted correctly in the browser so I decide to do a test.

First, I copy the text in the browser and paste it into a plain text editor, like NotePad. Then I save the file as test1.svg.

If I attempt to open test1.svg in my IE browser, the screen is blank.

Next, I copy the text initially shown in the browser and paste it into NotePad. This time I remove all white-space and CRLF from the file between the tags and I save the file as test2.svg. When I open this file in my IE browser I see the same graphic as shown in SS when the XSL file is run against the XML file.

If I uncomment the first line of my Page_Load function in the ASP.NET code, listed as
Response.AddHeader("Content-Type", "image/svg+xml");
and then run the app, my browser window is blank. This line prevents text from being written to the browser and instead it should display the graphic image described in the SVG document.

My question is this. How can I automatically strip out all of the whitespace and CRLF in the SVG that is passed to my browser.

In my XSL file you can see that I added the following line...
<xsl:strip-space elements="*"/>
Apparently, some white space remains since I see the same text written to my browser when I comment that top line in my Page_Load function and I still see a blank screen when I uncomment the same line. At the bottom of this post is the text that is written to my browser.

Any thoughts are appreciated...

1) XML file

<data>
<datum>23</datum>
<datum>94</datum>
<datum>55</datum>
</data>


2) XSL file

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="xml"/>
<xsl:strip-space elements="*"/>
<xsl:template match="/">
<svg xmlns:svg="http://www.w3.org/2000/svg" height="100" width="100" viewBox="0 0 100 100">
<xsl:for-each select="data/datum">
<rect x="{10*position()}" y="{100- .}" width="10" height="{.}" fill="red" stroke="black"/>
</xsl:for-each>
</svg>
</xsl:template>
</xsl:stylesheet>


3) ASP.NET file

<%@ 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>

*********************
Text written to my browser is as follows...

<?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>

Posttop
Ivan PedruzziSubject: xsl:strip-space
Author: Ivan Pedruzzi
Date: 29 Oct 2006 01:35 PM
Hi Glenn,

It' very unlikely that the presence of white-space prevent the rendering. Could you please post datum.xml and datum.xsl?


Ivan Pedruzzi
Stylus Studio Team

 
Topic Page 1 2 3 4 5 6 7 8 9 Go to previous topicPrev TopicGo to next topicNext Topic
Download A Free Trial of Stylus Studio 6 XML Professional Edition Today! Powered by Stylus Studio, the world's leading XML IDE for XML, XSLT, XQuery, XML Schema, DTD, XPath, WSDL, XHTML, SQL/XML, and XML Mapping!  
go

Log In Options

Site Map | Privacy Policy | Terms of Use | Trademarks
Stylus Scoop XML Newsletter:
W3C Member
Stylus Studio® and DataDirect XQuery ™are from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2016 All Rights Reserved.