Transform XML to Text file using XSLT

nasheer
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">
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:output method="text"/>
<xsl:strip-space elements="*"/>
<xsl:template match="*">
<xsl:apply-templates select="node()|@*"/>
<xsl:text> </xsl:text>
</xsl:template>
<xsl:template match="NewOrder/HeaderDetails">
<xsl:apply-templates select="*|@*"/>|
</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.
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">
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:output method="text"/>
<xsl:strip-space elements="*"/>
<xsl:template match="*">
<xsl:apply-templates select="node()|@*"/>
<xsl:text> </xsl:text>
</xsl:template>
<xsl:template match="NewOrder/HeaderDetails">
<xsl:apply-templates select="*|@*"/>|
</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.
0
Comments
-
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;
TimTim Whitaker | Senior NAV Consultant/Developer | The Software Workshop Ltd. | http://www.thesoftwareworkshop.com0 -
Hi Tim
Thanks lot. It works
Best Regards
Nasheer.0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions