Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Question Marks (???) in out put HTMl

357 views
Skip to first unread message

Zest4Quest

unread,
Mar 6, 2009, 11:10:01 AM3/6/09
to
Hi,
I am new to XSL.Could some one please tell me whay i am seeing ??? in my
output HTML?
The starting of my xml input and xslt is given below in case that has got
anything to do with it..

XSLT
--------
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxsl="urn:schemas-microsoft-com:xslt"
exclude-result-prefixes="msxsl">

<xsl:output method="html" indent="yes"/>

<xsl:template match="/">
<html >
<head>
<title>Untitled Page</title>
<style type="text/css">
.style2
{
width: 320px;
font-weight: bold;
}
.style3
{
width: 9%;
}
.tableStyle
{
width:100%; font-family: sans-serif;
font-size: 8.25px;
font-weight: normal;
}
</style>
</head>


<body bgcolor="#e7ecff" style =" font: 10pt sans-serif; font-style:
normal;" >
<br/>
<table width="100%">

<!--SOCIAL HISTORY-->
<xsl:for-each select="Assessment/PersonalSocialHistory">

XML
--------
<Assessment
xmlns:i="http://www.w3.org/2001/XMLSchema-instance"><Cardiovascular><AssessmentDateTime>2009-02-25T00:13:23.437</AssessmentDateTime><AssessmentIdentifier>1</AssessmentIdentifier><BlnEdemaLocationIsEnabled>false</BlnEdemaLocationIsEnabled><BlnEdemaOtherIsEnabled>false</BlnEdemaOtherIsEnabled><BlnPacemakerIsEnabled>false</BlnPacemakerIsEnabled><BlnPulsesEnabled>true</BlnPulsesEnabled><BlnReproducibleIsEnabled>false</BlnReproducibleIsEnabled><BruitsLocation
i:nil="true"/><CADelayedTime i:nil="true"/><CRNormalDelayed
i:nil="true"/><CapillaryRefill>1
</CapillaryRefill><CapillaryRefillGreaterThan3W
i:nil="true"/><CapillaryRefillLessThan3W
i:nil="true"/><CardioID>244</CardioID><CardioNotes
i:nil="true"/><CardioStatus>A</CardioStatus><ChestPain>1 </ChestPain>
.
.
.

Thanks in Advance..

Martin Honnen

unread,
Mar 6, 2009, 11:20:34 AM3/6/09
to
Zest4Quest wrote:

> I am new to XSL.Could some one please tell me whay i am seeing ??? in my
> output HTML?

How are you looking at the resulting HTML? Which XSLT processor do you use?


--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/

Martin Honnen

unread,
Mar 6, 2009, 11:36:44 AM3/6/09
to
Zest4Quest wrote:

> Like i said i am new to xslt..Not sure what a processor is...I am
> displaying the output html in a Microsoft Webbrowser control in a Windows
> form(C#).I created the XSLT using the Vstudio -> Add new item -> xslt
> got the xml by using DataContractSerializer class since the entity is a
> DataContract object.

How do you create the output HTML exactly? How do you load it in the
WebBrowser control?

Zest4Quest

unread,
Mar 6, 2009, 2:14:01 PM3/6/09
to
Hi Marin,
I have the following function in C# which transforms the XML.
The GenerateXML() returns a string that represents the xml...

public class XmlGenerator<T> where T : class
{
private T _dataContract;
public XmlGenerator(T dataContract)
{
_dataContract = dataContract;
}

/// <summary>
/// Generates the XML from the Object
/// </summary>
/// <returns></returns>
private string GenerateXml()
{
UnicodeEncoding uniEncoding = new UnicodeEncoding();
string buffer;

DataContractSerializer ser = new
DataContractSerializer(typeof(T));

StreamWriter stWriter = null;
MemoryStream memoryStream = new MemoryStream();
XmlTextWriter xmlWriter = new XmlTextWriter(memoryStream,
Encoding.Unicode);

stWriter = new StreamWriter(memoryStream);
ser.WriteObject(memoryStream, this._dataContract);

buffer = Encoding.ASCII.GetString(memoryStream.GetBuffer());

return
buffer.Replace(@"xmlns=""http://schemas.datacontract.org/2004/07/EDIM.DataContracts""", "");
}

public string TransformXmlFinal(string xSLTFileName)
{

XmlDataDocument d = new XmlDataDocument();
string sXML = this.GenerateXml();
d.LoadXml(this.GenerateXml());

XslCompiledTransform xslTransform = new XslCompiledTransform();

xslTransform.Load(xSLTFileName);

MemoryStream memoryStreamOutPut = new MemoryStream();
xslTransform.Transform(d, null, memoryStreamOutPut);
return Encoding.ASCII.GetString(memoryStreamOutPut.GetBuffer());
}
}

Thanks for your help
..

Zest4Quest

unread,
Mar 6, 2009, 2:31:03 PM3/6/09
to
I forgot to add this..the html text returned is then displayed in the
browswer control by setting it's DocumentText property to the text returned
by transform

Martin Honnen

unread,
Mar 7, 2009, 7:44:36 AM3/7/09
to
Zest4Quest wrote:

Don't use all those MemoryStreams, if you want a string then you can use
a StringWriter, there is no need to mess with MemoryStreams, Encodings,
byte arrays:

private string GenerateXml()
{
string generatedXml;

DataContractSerializer ser = new
DataContractSerializer(typeof(T));

using (StringWriter sw = new StringWriter())
{
using (XmlWriter xw = XmlWriter.Create(sw))
{
ser.WriteObject(xw, this._dataContract);
xw.Close();
}
generatedXml = sw.ToString();
}
return generatedXml;

}

public string TransformXmlFinal(string xSLTFileName)
{

string sXML = this.GenerateXml();

XslCompiledTransform xslTransform = new XslCompiledTransform();

xslTransform.Load(xSLTFileName);

StringWriter result = new StringWriter();

xslTransform.Transform(new XPathDocument(new
StringReader(sXML)), null, result);

return result.ToString();

}

That way I hope the question marks should no longer appear as I suspect
they occured by using Encoding.ASCII to decode a byte array in a
different encoding and perhaps containing a byte order mark.

Zest4Quest

unread,
Mar 8, 2009, 12:33:01 PM3/8/09
to
Thanks once again Martin.That Worked well.Only thing i had to do was continue
to use the following stmt.

since without that, for some reason gave me a blank html output.

Martin Honnen

unread,
Mar 8, 2009, 1:27:35 PM3/8/09
to
Zest4Quest wrote:
> Thanks once again Martin.That Worked well.Only thing i had to do was continue
> to use the following stmt.
> buffer.Replace(@"xmlns=""http://schemas.datacontract.org/2004/07/EDIM.DataContracts""", "");
>
> since without that, for some reason gave me a blank html output.

Well that "hack" is certainly not necessary if you learn to write XSLT
1.0 stylesheet dealing with default namespace declarations. So instead
of removing the xmlns declaration with string processing you would need
to fix your XSLT stylesheet to bind a prefix to that namespace and use
that prefix in XPath expressions and in XSLT match patterns to qualify
element names e.g.

<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0"
xmlns:dc="http://schemas.datacontract.org/2004/07/EDIM.DataContracts"
exclude-result-prefixes="dc">

<!-- now use prefix 'dc' in expressions and patterns -->

<xsl:template match="dc:foo">
<xsl:apply-templates select="dc:bar/">
<xsl:template>

<xsl:template match="dc:bar">
<xsl:value-of select="dc:baz"/>
</xsl:template>

</xsl:template>

So basically, in your stylesheet you need to replace all unqualified
element names 'foo' by 'dc:foo'. That way your stylesheet would work
without any need to preprocess the XML input with string replacement.

If you don't understand what I am suggesting above then post your XML
input and your stylesheet, then we can show you how to fix that.

0 new messages