{ Community }
  • Academy
  • Docs
  • Developers
  • Resources
    • Community Articles
    • Apigee on GitHub
    • Code Samples
    • Videos & eBooks
    • Accelerator Methodology
  • Support
  • Ask a Question
  • Spaces
    • Product Announcements
    • General
    • Edge/API Management
    • Developer Portal (Drupal-based)
    • Developer Portal (Integrated)
    • API Design
    • APIM on Istio
    • Extensions
    • Business of APIs
    • Academy/Certification
    • Adapter for Envoy
    • Analytics
    • Events
    • Hybrid
    • Integration (AWS, PCF, Etc.)
    • Microgateway
    • Monetization
    • Private Cloud Deployment
    • 日本語コミュニティ
    • Insights
    • IoT Apigee Link
    • BaaS/Usergrid
    • BaaS Transition/Migration
    • Apigee-127
    • New Customers
    • Topics
    • Questions
    • Articles
    • Ideas
    • Leaderboard
    • Badges
  • Log in
  • Sign up

Get answers, ideas, and support from the Apigee Community

  • Home /
  • Edge/API Management /
avatar image
1
Question by HS Bilgen · May 05, 2020 at 09:07 AM · 82 Views apigee edgeassign message policyxmljsontoxmlxsltxsl transform

Error with XSL Transform - XSLT-Transform.xsl failed with reason: "Process instruction target name cannot be xml at line 2(possibly around char 18)"

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.

proxy-flow.jpg (24.6 kB)
Comment
Add comment
10 |5000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by Apigeeks only
  • Viewable by the original poster
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Close

1 Answer

  • Sort: 
avatar image
1
Best Answer

Answer by Dino-at-Google   · May 05, 2020 at 04:24 PM

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.

Comment
Add comment Show 2 · Link
10 |5000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by Apigeeks only
  • Viewable by the original poster
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Dino-at-Google ♦♦   · May 05, 2020 at 04:53 PM 0
Link

Yup, I just tried it and got the same error as you reported. Then tried it with my suggestion and it worked.

By the way, Your problem is exacerbated by the fact that the OmitXmlDeclaration option is apparently not working in the JSONToXML policy. Theoretically if you use this opion in the J2X policy, then instead of getting

<?xml version="1.0" encoding="UTF-8"?>...

...in your output XML, you would just get the raw XML with no declaration. The XSL policy is complaining about that declaration.

I know the documentation describes the OmitXmlDeclaration option, but... apparently our product has gotten out of sync with the documentation in small ways. We've paused our release due to the disruption related to COVID, and in the confusion I'm guessing we published the doc updates, but we did not release the product updates concurrently.

at some point soon, I expect that the Apigee engineers will push the updates into production, and when that happens, the OmitXmlDeclaration option will start working as documented.

This discrepancy shouldn't be a blocker for you, with the advice I've given up above.

avatar image HS Bilgen · May 06, 2020 at 07:50 AM 0
Link

Hi @Dino @Dino-at-Google , thank you for your reply. I was expecting J2X policy to avoid XML declaration which I thought that was an issue with XSL Transform. Apparently it's not omitting that at all.

But that's all good for now and without that newline in Assign-Message entire flow works. I was thinking to open an issue to apigee but not needed anymore.

It would be nice if documentation of XSL Transform Troubleshooting includes error type as I explained in question itself.

Thanks for initiative with updates as well.

Follow this Question

Answers Answers and Comments

131 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

​Condition not working in Assign Message Policy. Is any possibility to include conditional logic in an AssignMessage policy? 2 Answers

unable to convert Xml To Json format using xslt 1 Answer

How to get a Json response by passing input in Headers of PostMan. 1 Answer

Conversion of Query Parameters to XML 1 Answer

I want to create an api proxy which returns different set of columns for different query param / class 2 Answers

  • Products
    • Edge - APIs
    • Insights - Big Data
    • Plans
  • Developers
    • Overview
    • Documentation
  • Resources
    • Overview
    • Blog
    • Apigee Institute
    • Academy
    • Documentation
  • Company
    • Overview
    • Press
    • Customers
    • Partners
    • Team
    • Events
    • Careers
    • Contact Us
  • Support
    • Support Overview
    • Documentation
    • Status
    • Edge Support Portal
    • Privacy Policy
    • Terms & Conditions
© 2021 Apigee Corp. All rights reserved. - Apigee Community Terms of Use - Powered by AnswerHub
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Create an article
  • Post an idea
  • Spaces
  • Product Announcements
  • General
  • Edge/API Management
  • Developer Portal (Drupal-based)
  • Developer Portal (Integrated)
  • API Design
  • APIM on Istio
  • Extensions
  • Business of APIs
  • Academy/Certification
  • Adapter for Envoy
  • Analytics
  • Events
  • Hybrid
  • Integration (AWS, PCF, Etc.)
  • Microgateway
  • Monetization
  • Private Cloud Deployment
  • 日本語コミュニティ
  • Insights
  • IoT Apigee Link
  • BaaS/Usergrid
  • BaaS Transition/Migration
  • Apigee-127
  • New Customers
  • Explore
  • Topics
  • Questions
  • Articles
  • Ideas
  • Badges