Anyone can help me out with XSL Transform issues?
I have a XML payload after JSON2XML conversion and used Assign-Message to add that XML into message to process with XSL Transform policy to get an expected outcome of XSLT. While any online XSLT tool successfully transforms that XML unless apigee throws an policy error as below;
{"fault":{"faultstring":"Evaluation of XSL XSLT-Transform.xsl failed with reason: \"Process instruction target name cannot be xml at line 2(possibly around char 18)\"","detail":{"errorcode":"steps.xsl.XSLEvaluationFailed"}}}
If there is known issues with XSL Transform please let me know. Adding Proxy configuration below;
My JSON2XML policy as follows;
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <JSONToXML async="false" continueOnError="false" enabled="true" name="J2X-InputDoc"> <DisplayName>J2X-InputDoc</DisplayName> <Options> <OmitXmlDeclaration>true</OmitXmlDeclaration> </Options> <OutputVariable>XMLInput</OutputVariable> <Source>JSONContent</Source> </JSONToXML>
Assign-Message as follows;
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <AssignMessage async="false" continueOnError="false" enabled="true" name="AM-Transform"> <DisplayName>AM-Transform</DisplayName> <Properties/> <Set> <Headers> <Header name="Content-Type">application/xml</Header> </Headers> <Payload contentType="application/xml" variablePrefix="@" variableSuffix="#"> @XMLInput# </Payload> <StatusCode>200</StatusCode> <ReasonPhrase>OK</ReasonPhrase> </Set> <IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables> <AssignTo createNew="true" type="request">XMLTransform</AssignTo> </AssignMessage>
XSL Transform policy as follows;
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <XSL async="false" continueOnError="false" enabled="true" name="XSLT-Transform"> <DisplayName>XSLT-Transform</DisplayName> <Properties/> <Source>XMLTransform</Source> <ResourceURL>xsl://XSLT-Transform.xsl</ResourceURL> <Parameters ignoreUnresolvedVariables="true"/> <OutputVariable/> </XSL>
Everything seems to me correctly configured I'm not sure If I am missing anything in proxy flow to see result of XSL Transform.
Can anyone help me out on this?
@Dino @Dino-at-Google @Geir Sjurseth @Mike Dunker @Google
Note: I am using apigee cloud.
Solved! Go to Solution.
Judging from the error message, the XSL processor thinks there is an unexpected processing instruction in the document, somewhere around line 2.
BTW, the processing instruction is the string that looks something like this:
<?xml version="1.0" encoding="UTF-8"?>
XML rules say that has to be the first thing in the document. Why would a processing instruction appear on line 2?
Looking at the AssignMessage policy, it seems you are blatting the XML string into a message, using the Payload element. And I'll bet that is putting a newline and whitespace before the XML processing instruction.
What I would try:
Modify your AssignMessage policy to not insert a newline and whitespace before XMLInput.
<AssignMessage name="AM-Transform"> <Set> <Payload contentType="application/xml">{XMLInput}</Payload> </Set> <AssignTo createNew="true" type="request">XMLTransform</AssignTo> </AssignMessage>
See if that works.
I don't know what else is in that XMLInput string, so... you may need to trim it or do other stuff to it before blatting it into the message.