Solved Solved

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

hsnbilgen
Participant III

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;

9847-proxy-flow.jpg

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 Solved
1 3 174
1 ACCEPTED SOLUTION
Solved Solved

dchiesa1
Staff

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.

View solution in original post

Solved Solved
1 2 0
3 REPLIES 3
Solved Solved

dchiesa1
Staff

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.

View solution in original post

Solved Solved
1 2 1

dchiesa1

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.

0 0 0

hsnbilgen

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.

0 0 0
Top Labels in this Space
Top Solution Authors