Logic Apps - Transform XML (XSLT) using it to create a CSV (text) file.

Marek Dąbrowski 1 Reputation point
2020-04-14T23:01:18.677+00:00

Hello,

I try to do a simple transform XML to CSV (text output) using Logic App 'Transfrom XML' functionality.
So i created right maps that work in XML Transformation (in Notepad++) and also other converter like https://www.freeformatter.com/ etc.

SIMPLE XML that i try:

<?xml version=&#34;1.0&#34; encoding=&#34;UTF-8&#34; standalone=&#34;no&#34;?>
<CATALOG>
<PLANT>
<COMMON>Bloodroot</COMMON>
<BOTANICAL>Sanguinaria canadensis</BOTANICAL>
<ZONE>4</ZONE>
<LIGHT>Mostly Shady</LIGHT>
<PRICE>$2.44</PRICE>
<AVAILABILITY>031599</AVAILABILITY>
</PLANT>
<PLANT>
<COMMON>Columbine</COMMON>
<BOTANICAL>Aquilegia canadensis</BOTANICAL>
<ZONE>3</ZONE>
<LIGHT>Mostly Shady</LIGHT>
<PRICE>$9.37</PRICE>
<AVAILABILITY>030699</AVAILABILITY>
</PLANT>
</CATALOG>

One of the .XSLT idea that should work in Logic App:

<?xml version=&#34;1.0&#34;?>
<xsl:stylesheet version=&#34;1.0&#34; xmlns:xsl=&#34;http://www.w3.org/1999/XSL/Transform&#34;>
<xsl:output method=&#34;text&#34;/>
<xsl:variable name='newline'><xsl:text>
</xsl:text></xsl:variable>
<xsl:variable name='comaVar'><xsl:text>,</xsl:text></xsl:variable>
<xsl:template match=&#34;/CATALOG&#34;>
<xsl:value-of select=&#34;concat('COMMON,BOTANICAL,ZONE,LIGHT,PRICE,AVAILABILITY',$newline)&#34;/>
<xsl:for-each select=&#34;./PLANT&#34;>
<xsl:value-of select=&#34;concat('&quot;',./COMMON,'&quot;',$comaVar,'&quot;',./BOTANICAL,'&quot;',$comaVar,./ZONE,$comaVar,'&quot;',./LIGHT,'&quot;',$comaVar,./PRICE,$comaVar,./AVAILABILITY,$newline)&#34;/>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>

What i should achieve:

COMMON,BOTANICAL,ZONE,LIGHT,PRICE,AVAILABILITY
"Bloodroot","Sanguinaria canadensis",4,"Mostly Shady",$2.44,031599
"Columbine","Aquilegia canadensis",3,"Mostly Shady",$9.37,030699

Every time i try it on diffrent ideas in .xslt i have same 'BadRequest' info in Logic App Designer:

{
"statusCode": 400,
"headers": {
"Pragma": "no-cache",
"Cache-Control": "no-cache",
"Date": "Tue, 14 Apr 2020 22:24:16 GMT",
"Server": "Microsoft-IIS/10.0",
"X-Powered-By": "ASP.NET",
"Content-Length": "5628",
"Content-Type": "application/json",
"Expires": "-1"
},
"body": {
"Code": "InvalidXsltContent",
"Message": "An error occurred while processing map. 'Token Text in state Start would result in an invalid XML document. Make sure that the ConformanceLevel setting is set to ConformanceLevel.Fragment or ConformanceLevel.Auto if you want to write an XML fragment. '",
"Details": [
{
"Code": "InvalidXsltContent",
"Message": "{\"StatusCode\":400,\"ErrorCode\":7,\"Details\":null,\"Message\":\"An error occurred while processing map. 'Token Text in state Start would result in an invalid XML document. Make sure that the ConformanceLevel setting is set to ConformanceLevel.Fragment or ConformanceLevel.Auto if you want to write an XML fragment. '\",\"Data\":{},\"InnerException\":{\"ClassName\":\"System.InvalidOperationException\",\"Message\":\"Token Text in state Start would result in an invalid XML document. Make sure that the ConformanceLevel setting is set to ConformanceLevel.Fragment or ConformanceLevel.Auto if you want to write an XML fragment. \",\"Data\":null,\"InnerException\":null,\"HelpURL\":null,\"StackTraceString\":\" at System.Xml.XmlWellFormedWriter.ThrowInvalidStateTransition(Token token, State currentState)\r\n at System.Xml.XmlWellFormedWriter.AdvanceState(Token token)\r\n at System.Xml.XmlWellFormedWriter.WriteString(String text)\r\n at System.Xml.Xsl.Runtime.XmlRawWriterWrapper.WriteString(String text)\r\n at System.Xml.Xsl.Runtime.XmlQueryOutput.WriteString(String text, Boolean disableOutputEscaping)\r\n at plantcatalog_tocsv.<xsl:template match=\\"/\\">(XmlQueryRuntime {urn:schemas-microsoft-com:xslt-debug}runtime, XPathNavigator {urn:schemas-microsoft-com:xslt-debug}current)\r\n at plantcatalog_tocsv.Root(XmlQueryRuntime {urn:schemas-microsoft-com:xslt-debug}runtime)\r\n at plantcatalog_tocsv.Execute(XmlQueryRuntime {urn:schemas-microsoft-com:xslt-debug}runtime)\r\n at System.Xml.Xsl.XmlILCommand.Execute(Object defaultDocument, XmlResolver dataSources, XsltArgumentList argumentList, XmlSequenceWriter results)\r\n at System.Xml.Xsl.XmlILCommand.Execute(Object defaultDocument, XmlResolver dataSources, XsltArgumentList argumentList, XmlWriter writer)\r\n at System.Xml.Xsl.XslCompiledTransform.Transform(XmlReader input, XsltArgumentList arguments, XmlWriter results)\r\n at Microsoft.Azure.Function.Transform.XsltTransformer.TransformToXmlInternal(ProcessedXslt1 processedXslt, XmlReader inputXmlReader, XsltArgumentList xsltArguments, Nullable1 transformOptions) in X:\\bt\\1075184\\repo\\src\\functions\\Scripts\\Function.Transform\\XsltTransformer.cs:line 235\r\n at Microsoft.Azure.Function.Transform.XsltTransformer.TransformInternal(ProcessedXslt1 processedXslt, XmlReader inputXmlReader, XsltArgumentList xsltArguments, Nullable1 transformOptions) in X:\\bt\\1075184\\repo\\src\\functions\\Scripts\\Function.Transform\\XsltTransformer.cs:line 174\",\"RemoteStackTraceString\":null,\"RemoteStackIndex\":0,\"ExceptionMethod\":\"8\nThrowInvalidStateTransition\nSystem.Xml, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089\nSystem.Xml.XmlWellFormedWriter\nVoid ThrowInvalidStateTransition(Token, State)\",\"HResult\":-2146233079,\"Source\":\"System.Xml\",\"WatsonBuckets\":null},\"TargetSite\":{\"Name\":\"TransformInternal\",\"AssemblyName\":\"Microsoft.Azure.Function.Transform, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null\",\"ClassName\":\"Microsoft.Azure.Function.Transform.XsltTransformer\",\"Signature\":\"Microsoft.Azure.Function.Transform.XsltTransformOutput TransformInternal(Microsoft.Azure.Function.Common.Xml.ProcessedXslt1[System.Xml.Xsl.XslCompiledTransform], System.Xml.XmlReader, System.Xml.Xsl.XsltArgumentList, System.Nullable1[Microsoft.Azure.Function.Common.Xml.XsltTransformOptions])\",\"Signature2\":\"Microsoft.Azure.Function.Transform.XsltTransformOutput TransformInternal(Microsoft.Azure.Function.Common.Xml.ProcessedXslt1[[System.Xml.Xsl.XslCompiledTransform, System.Xml, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]], System.Xml.XmlReader, System.Xml.Xsl.XsltArgumentList, System.Nullable1[[Microsoft.Azure.Function.Common.Xml.XsltTransformOptions, Microsoft.Azure.Function.Common, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35]])\",\"MemberType\":8,\"GenericArguments\":null},\"StackTrace\":\" at Microsoft.Azure.Function.Transform.XsltTransformer.TransformInternal(ProcessedXslt1 processedXslt, XmlReader inputXmlReader, XsltArgumentList xsltArguments, Nullable1 transformOptions) in X:\\bt\\1075184\\repo\\src\\functions\\Scripts\\Function.Transform\\XsltTransformer.cs:line 214\r\n at Microsoft.Azure.Function.Transform.XsltTransformer.<Transform>d__9.MoveNext() in X:\\bt\\1075184\\repo\\src\\functions\\Scripts\\Function.Transform\\XsltTransformer.cs:line 92\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1.ConfiguredTaskAwaiter.GetResult()\r\n at Microsoft.Azure.Function.Transform.TransformRequestProcessor.<ProcessTransformRequest>d__2.MoveNext() in X:\\bt\\1075184\\repo\\src\\functions\\Scripts\\Function.Transform\\TransformRequestProcessor.cs:line 49\",\"HelpLink\":null,\"Source\":\"Microsoft.Azure.Function.Transform\",\"HResult\":-2146233088}",
"Details": null,
"InnerError": null
}
],
"InnerError": null
}
}

Azure Logic Apps
Azure Logic Apps
An Azure service that automates the access and use of data across clouds without writing code.
2,824 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. BhargaviAnnadevara-MSFT 5,446 Reputation points
    2020-04-20T07:22:03.483+00:00

    Hello @Marek Dąbrowski ,

    Thanks for the question. Azure Logic Apps has not yet migrated to the Q&A platform, but is active on MSDN:

    https://social.msdn.microsoft.com/Forums/en-US/home?forum=azurelogicapps

    Please post your question there so you can get assistance from the community.

    0 comments No comments