Chris
Chris

Reputation: 254

ColdFusion - pass XML as parameter to xmlTransform() in CF10

Good day -

In ColdFusion 9, we could pass XML parameters to xmlTransform(), like this:

<cfxml variable="parm">
  <users>
     <user>Joe Blow</user>
     <user>Jane Doe</user>
  </users>
</cfxml>

<cfset params=structNew()>
<cfset params["users"]=parm>
<cfset newXML=xmlTransform(xmlFile,xslFile,params)>

In the XSL then, we could accept the "users" argument:

<xsl:param name="users" select="." />

And use it as a variable, run XPath on it, etc.

However, with ColdFusion 10, passing an XML argument to any XSL results in an error. It is quite unhelpful, and none of the error logs show any detail.

The error shown is simply:

    An error occured while Transforming an XML document. 

and

coldfusion.xml.XmlProcessException: An error occured while Transforming an XML document. at coldfusion.xml.XmlProcessor.doTransform(XmlProcessor.java:508) at coldfusion.xml.XmlProcessor.access$100(XmlProcessor.java:82) at coldfusion.xml.XmlProcessor$3.run(XmlProcessor.java:455) at java.security.AccessController.doPrivileged(Native Method) at coldfusion.xml.XmlProcessor.transform(XmlProcessor.java:451) at coldfusion.xml.XmlProcessor.transform(XmlProcessor.java:440) at coldfusion.runtime.CFPage.XmlTransform(CFPage.java:359) at cftestxml2ecfm41929416.runPage(E:\test\testxml.cfm:36) at coldfusion.runtime.CfJspPage.invoke(CfJspPage.java:244) at coldfusion.tagext.lang.IncludeTag.doStartTag(IncludeTag.java:444) at coldfusion.filter.CfincludeFilter.invoke(CfincludeFilter.java:65) at coldfusion.filter.IpFilter.invoke(IpFilter.java:64) at coldfusion.filter.ApplicationFilter.invoke(ApplicationFilter.java:443) at ) ... (etc)

I've narrowed it down to specifically the action of passing XML as an argument. If it's changed to a string instead of XML, it "works" in the sense that it doesn't get this error. That's fine for an empty XSLT, but of course we need it to be passed as XML so that we can e.g. use XPath on the data.

Has ColdFusion 10 changed so that it no longer allows XML parameters to xmlTransform()? Any help is greatly appreciated.

Upvotes: 1

Views: 1201

Answers (2)

Jeff Peters
Jeff Peters

Reputation: 1

Another important safety tip:

If you're running CF on Linux, keep in mind that CF changes all struct keys to uppercase.

For example:

In the XSL, the <xsl:param name="PARMNAME"> element and the $PARMNAME references in the body need to have all parameter names converted to uppercase.

Upvotes: 0

Adam
Adam

Reputation: 51

I saw the same thing and this still fails - but noticed it failed because the "value" of the parameter struct happened to be a number.

For example, <cfset xslparameters["regionID"] = 223> fails, as does <cfset xslparameters["regionID"] = "223">

The trick is to force wrap as a string: <cfset xslparameters["regionID"] = ToString("223")>

or in my case technically,

<cfset xslparameters["regionID"] = "#ToString(serviceRegion.region_id)#">

Upvotes: 1

Related Questions