How to get a data in xslt from the context variable which was set in javascript policy.

Not applicable

How to get a data in xslt from the context variable which was set in javascript policy.

I have javascript policy which is modifying data and set to some context variable named (headers) then I have xslt policy .I need to use the data(headers)in xslt.

1 1 2,039
1 REPLY 1

Can you clarify further?

What is contained within the context variable "headers"?

When you say "I need to use the data(headers) in xslt"... do you mean you wish to use the data as XSLT parameters? Or as the source (input) to the XSLT ?

Parameters

If you want to use the value of a context variable inside an XSL parameter, then the syntax is like this:

XSL policy:

<XSL name="XSL-XformRequest">
  <OutputVariable>request.content</OutputVariable>
  <Parameters ignoreUnresolvedVariables="true">
    <Parameter name="param1" ref="context-variable-goes-here"/>
    <Parameter name="param2" ref="another-context-variable-here"/>
  </Parameters>
  <ResourceURL>xsl://XformRequest.xsl</ResourceURL>
  <Source>request</Source>
</XSL> 

and the XSL itself looks like:

<xsl:stylesheet
    version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
    >
  <xsl:param name="param1" select="''"/>
  <xsl:param name="param2" select="''"/>
  <xsl:output
      method="xml"
      omit-xml-declaration="yes"
      indent="no"
      media-type="string"/>
  ...

Source

If you want to use the context variable as an XML source for the XSLT, then you need to store it in the content of a Message. The XSL policy accepts a Source element, and the value of the Source element must be a variable name. The variable must be of type "Message". The body of the Message must be XML and the content-type must be application/xml. In JS, setting the appropriate Message looks like this:

  var bodyXml = '<root><child1/><child2/></root>'; 

  var req = new Request('http://foo/bar', // value does not matter
                'POST', 
                {'Content-Type':'application/xml'}, 
                bodyXml);
  context.setVariable('myRequest', myRequest);

...and then you would configure your XSL policy like this:

<XSL name="XSL-XformRequest">
  <OutputVariable>request.content</OutputVariable>
  <ResourceURL>xsl://XformRequest.xsl</ResourceURL>
  <Source>myRequest</Source>
</XSL> 

...and the XSL can be whatever you like.

The actual values for the verb ('POST' in my example) and the URL ('http://foo/bar' in my example) don't matter, for the purposes of the XSL. You just need the body content and the content-type.

On further consideration, I think the verb should not matter but.... a body applies only to PUT or POST, so it is possible that one of those two verbs is required.