XSLT Transforming XML to HTML .NET - Forum - OpenEdge Development - Progress Community

XSLT Transforming XML to HTML .NET

 Forum

XSLT Transforming XML to HTML .NET

This question is not answered

Hi All 

I am using the following code to transform an XML document to a HTML document using .NET classes:

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

DEF VAR lv-MyTransform AS System.Xml.Xsl.XslCompiledTransform NO-UNDO.
DEF VAR lv-myXSLTStringReader AS System.IO.StringReader NO-UNDO.
DEF VAR lv-myXMLStringReader AS System.IO.StringReader NO-UNDO.
DEF VAR lv-myStringWriter AS System.IO.StringWriter NO-UNDO.

DEF VAR lv-MyXMLReader AS System.Xml.XmlReader NO-UNDO.
DEF VAR lv-myXMLWriter AS System.Xml.XmlWriter NO-UNDO.

DEF VAR lv-XMLString AS LONGCHAR NO-UNDO.
DEF VAR lv-Output AS LONGCHAR NO-UNDO.
DEF VAR lv-XML-Doc AS HANDLE NO-UNDO.

CREATE X-DOCUMENT lv-xml-doc.

lv-xml-doc:LOAD("file", "c:\openedge\wrk\openaccess\sds_compmaint.xml", FALSE).
lv-xml-doc:SAVE("LONGCHAR", lv-XMLString).

lv-myXMLStringReader = NEW System.IO.StringReader(lv-xmlString).

lv-MyTransform = new System.Xml.Xsl.XslCompiledTransform().
lv-Mytransform:Load("c:\openedge\wrk\custom\highways_england\ie\sds\sds_template.xsl").

lv-myStringWriter = NEW System.IO.StringWriter().

lv-MyXMLReader = System.Xml.XmlReader:CREATE(lv-myXMLStringReader).

lv-MyXmlWriter = System.Xml.XmlWriter:CREATE(lv-myStringWriter, lv-Mytransform:OutputSettings).

lv-Mytransform:Transform(lv-MyXMLReader,lv-myXMLWriter).

lv-Output = lv-myStringWriter:ToString().

OUTPUT TO "c:\openedge\wrk\dotnet_transform.html".
EXPORT lv-Output.
OUTPUT CLOSE.

<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

The issue is some of the escaped <XSL:text> is not escaped correctly and comes out as &nbsp; in the transformed HTML.

E.g. 

<title>Highways &nbsp;|&nbsp;Asset Details</title>

Sample XML

sds_compmaint.xml

All Replies
  • We do something similar. The only difference I see is that you are sending the output to an xmlwriter which will probably think   is meaningful, when I think you want a textwriter (System.IO.TextWriter).

  • Tried it with StringWriter and i get the same result.

    The only way that seems to work is to use the following techniques in your XSL file:

    <xsl:text> </xsl:text>

    instead of

    <xsl:text disable-output-escaping="yes">&nbsp;</xsl:text>

    and if you don't want self closing tags use <xsl:comment></xsl:comment>

    e,g,

    <script src="/cornwallhousing/shared/jquery/js/jquery-1.10.2.min.js" type="text/javascript"><xsl:comment></xsl:comment></script>

  • It may help if you also post your xsl.