Converting to text file after XSL transformation AX 2012

Question Status

Alok Shrestha asked a question on 22 Aug 2013 8:51 AM

I managed to perform the XSLT transformation in an input XML file and generate the transformed output XML file. Now, the requirement I am getting is that the output file should be a text file instead of a XML file. Is there any standard functionality to generate the transformed text file instead of XML file in AX 2012?

Martin Dráb responded on 22 Aug 2013 11:02 AM

Yes, that's fully supported by XSLT. For example, try this template with your message from the previous question:

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="">   <xsl:output method="text" encoding="utf-8"/>   <xsl:template match="Message:Envelope">     <xsl:value-of select="Message:Body"/>   </xsl:template> </xsl:stylesheet>

Also, please consider closing your previous question as answered.

Alok Shrestha responded on 22 Aug 2013 11:14 AM

I tried as you have mentioned and it just works perfect in visual studio but when I try the same thing in the AX 2012, it just produces the .xml file.

Martin Dráb responded on 22 Aug 2013 12:26 PM

I tried a simple example and it works for me. Because you didn't tell us what you're doing, I have no idea what you're doing wrong.

Alok Shrestha responded on 22 Aug 2013 12:34 PM

I am trying to implement the standard positive pay functionality that comes with cumulative updates 6 in AX 2012. The requirement is that I need to generate the .txt file instead of .xml file after xslt transformation. I thought I can just generate the .txt file by change the method attribute to "text" instead of "xml" in xslt file but AX 2012 keeps on storing .xml file only, not the .txt file. Did you generate the .txt file in AX 2012 only?

Martin Dráb responded on 22 Aug 2013 12:51 PM

I'm confused. Are you talking about transformation to plain text or saving a file with .txt extension?

Alok Shrestha responded on 22 Aug 2013 12:54 PM

Sorry for the confusion. I am talking about the transformation to the plain text and the file should be saved with .txt extension. It should just be a simple .txt file with plain text in it.

Martin Dráb responded on 22 Aug 2013 1:01 PM

About transformation, you said it already worked for you in VS, you just have to find out what you have wrong in AX. I don't have enough information to reproduce the problem.

About file extension, that's not supported. You would have to modify the standard file system adapter or create a custom one (it's defined in AifFileSystemSendAdapter.getNewOutFileName()).

Andrew Martin responded on 26 Mar 2014 11:48 AM

Martin - I came across this question as I am having the same difficulty implementing positive pay in 2012.  The issue is that the output of the xslt transformation is still continuing to be wrapped in an AIF Message:

<?xml version="1.0" encoding="UTF-8"?><Envelope xmlns=""><Header><MessageId>{AD130A63-D1FB-46AB-8844-00AC470066F4}</MessageId><Action>><Body><MessageParts xmlns=""><Document xmlns="urn:iso:std:iso:20022:tech:xsd:pain.001.001.02" xmlns:xsi="">

0003456700004000000000000000120110203ADDITIONAL DATA                Property Management                                         PAYEE 2                                                              

0003456700000680000000000000220110203ADDITIONAL DATA                City Power & Light                                          PAYEE 2                                                              

0003456700007800000000000000320110202ADDITIONAL DATA                City-wide Advertising                                       PAYEE 2                              

The file specification that we are working on for positive is a straight text file so the XML Message block cannot be included.

How do we get rid of that?  Do we have to apply a .Net assembly in the pipeline after the xslt transform?  The .Net assembly would be tasked with striping the XML out.  Something similar to what occurs when you import a CSV and need to convert to XML, just the reverse.  Thanks.


Alok Shrestha responded on 26 Mar 2014 12:04 PM


              As I started this thread, I am writing what I did to fix this issue.  I used .NET assembly directly in the AifFileSystemSendAdapter class with some conditions to achieve similar requirement. I just used .NET XSLCompiledTransform class along with XSL transformation as below to transfer the XML file to .txt file. 

System.IO.TextWriter textwriter;

System.Xml.Xsl.XslCompiledTransform managedTransform;

managedTransform.Load(xslFile,xslt_settings,new System.Xml.XmlUrlResolver());

textwriter= new System.IO.StreamWriter(ppFilePath,false,System.Text.Encoding::get_Default());




Andrew Martin responded on 26 Mar 2014 12:39 PM


I agree that your solution will work, but it seems like a fairly heavy handed solution that I'm sure Microsoft did not have in mind when they decided to use the AIF platform for positive pay.  I'll go down that path if I need to, but I'd like see if Martin has a comment on this.

Thanks for posting your solution.


Martin Dráb responded on 27 Mar 2014 1:20 AM

You can inject transformations in two different places:

  1. Pipelines (supported in previous versions too) - transform message body
  2. Transforms (new in AX2012) - transform the whole message (including headers)

See About the AIF Pipeline and Transforms for details.

You mentioned a pipeline, but it seems that you want a transform.