Google групе више не подржавају нове Usenet постове ни праћења. Претходни садржај остаје видљив.

Problems with XSLT processing of XML

3 прегледа
Пређи на прву непрочитану поруку

Hans P. Dramstad

непрочитано,
6. 10. 2002. 19:58:086.10.02.
I end up with the following error trying to run my Delphi (D7 Developer with
MSXML4.0) program: "The style sheet does not contain a document element. The
style sheet may be empty, or may not be well formed".

The XML (same XML and XSLT file) processing works fine in XMLSpy.

Any help here will be greatly appreciated - Thanks.

DELPHI CODE,
----------------
function DoTransform(const xml, xsl : string ): string;
var
XMLDoc : IXMLDOMDocument;
XSLDoc : IXMLDOMDocument;
Template : IXSLTemplate;
Processor : IXSLProcessor;
begin
Result := '';
try
XMLDoc := CoFreeThreadedDOMDocument40.Create;
XSLDoc := CoFreeThreadedDOMDocument40.Create;
XMLDoc.load(xml); // I have checked that xml contains what is expected
(OK)
XSLDoc.load(xsl); // I have checked that xslcontains what is expected
(OK)
Template := CoXSLTemplate40.Create;
Template.stylesheet := XSLDoc; // THIS LINE FAILS ALL THE TIME (Error
message given above)?????
Processor := Template.createProcessor;
Processor.input := XMLDoc;
Processor.transform;
result := Processor.output;
finally
XMLDoc := nil;
XSLDoc := nil;
end;
end;

XSLT file,
----------
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:template match="/">
<HTML>
<BODY>
<xsl:for-each select="vehicles/car">
<xsl:value-of select="name"/>, <xsl:value-of select="manufacturer"/>,
<xsl:value-of select="price"/><br>
</xsl:for-each>
</BODY>
</HTML>
</xsl:template>
</xsl:stylesheet>

XML file,
---------
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="F:\Delphi\Sample\vehicles.xsl"?>
<vehicles>
<type>Cars</type>
<car><name>Commodore</name><manufacturer>Holden</manufacturer><price>38,000<
/price>
</car>
<car><name>Falcon</name><manufacturer>Ford</manufacturer><price>36,000</pric
e>
</car>
<car><name>Verada</name><manufacturer>Mitsubishi</manufacturer><price>36,500
</price>
</car>
</vehicles>

Kind Regards Hans P. Dramstad


Stig Johansen

непрочитано,
6. 10. 2002. 22:56:116.10.02.
Hi.

"Hans P. Dramstad" <h...@mind2map.com> wrote in message
news:3da0cd41$1...@newsgroups.borland.com...


> I end up with the following error trying to run my Delphi (D7 Developer
with
> MSXML4.0) program: "The style sheet does not contain a document element.
The
> style sheet may be empty, or may not be well formed".
>
> The XML (same XML and XSLT file) processing works fine in XMLSpy.
>
> Any help here will be greatly appreciated - Thanks.
>
> DELPHI CODE,
> ----------------
> function DoTransform(const xml, xsl : string ): string;
> var
> XMLDoc : IXMLDOMDocument;
> XSLDoc : IXMLDOMDocument;

Try:
XMLDoc : IXMLDocument ;
XSLDoc : IXMLDocument ;

> begin
> Result := '';
> try
> XMLDoc := CoFreeThreadedDOMDocument40.Create;
> XSLDoc := CoFreeThreadedDOMDocument40.Create;

Try:
XMLDoc := NewXMLDocument ;
XSLDoc := NewXMLDocument ;

> XMLDoc.load(xml); // I have checked that xml contains what is expected
> (OK)
> XSLDoc.load(xsl); // I have checked that xslcontains what is expected
> (OK)

try:
XMLDoc.XML.Text := xml;
XSLDoc.XML.Text := xsl;

> result := Processor.output;
try:
XMLDoc.DocumentElement.TransformNode(XSLDoc.DocumentElement,result);

> finally
> XMLDoc := nil;
> XSLDoc := nil;
> end;
> end;

--

Med venlig hilsen/Best regards
Stig Johansen
Stig.J...@udvikling.it.dk
(remove dot dk)

0 нових порука