Transform XML to Text file using XSLT

nasheernasheer Member Posts: 78
Dear All

I used the below XSL to transform the XML to text

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"&gt;
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:output method="text"/>
<xsl:strip-space elements="*"/>

<xsl:template match="*">
<xsl:apply-templates select="node()|@*&quot;/>
<xsl:text> </xsl:text>
</xsl:template>

<xsl:template match="NewOrder/HeaderDetails">
<xsl:apply-templates select="*|@*&quot;/>|
</xsl:template>
</xsl:stylesheet>


the code working fine using EditX XML editor.

But no file generated in Navision, below is the code.

XMLDocOut,XMLDocIn,XSLTemplate > 'Microsoft XML, v3.0'.DOMDocument30
XSLTemplateNode > 'Microsoft XML, v3.0'.IXMLDOMNode

IF NOT XMLDocIn.load('X:\XSLT Test\Output\WebOrdHead.XML') THEN
MESSAGE('XML Output File NOT Loaded');
IF NOT XSLTemplate.load('X:\XSLT Test\Template\xmlToTextTemplate.xsl') THEN
MESSAGE('XML to Text Template NOT Loaded');

XSLTemplateNode := XSLTemplate.documentElement;
XMLDocOut.async := FALSE;
XMLDocIn.transformNodeToObject(XSLTemplateNode,XMLDocOut);
XMLDocOut.save(g_txtFileNameText);


Can anyone please help me to solve this issue?

Regards
Nasheer.

Comments

  • whitaker_timwhitaker_tim Member Posts: 23
    Hi Nasheer,

    I think the issue here is more related to the output file, in this case a text file format not an xml file format. I would suggest that a outstream be used to assist to store the output, try the code below with an outstream in place of the outbound xml file.

    XSLTemplateNode := XSLTemplate.documentElement;
    OutFile.CREATE('X:\XSLT Test\Output\Output.txt');
    OutFile.CREATEOUTSTREAM(OutSt);
    XMLDocIn.transformNodeToObject(XSLTemplateNode,OutSt);
    OutFile.CLOSE;

    Tim
    Tim Whitaker | Senior NAV Consultant/Developer | The Software Workshop Ltd. | http://www.thesoftwareworkshop.com
  • nasheernasheer Member Posts: 78
    Hi Tim

    Thanks lot. It works :)

    Best Regards
    Nasheer.
Sign In or Register to comment.