XSLT script not pulling values as expected from JSON - not being used correctly w /Root??

json0315.txtxsltscript.txt

Solved Solved
0 5 192
1 ACCEPTED SOLUTION

Hi Frank

I think you can get what you want with a series of xsl:if elements.

If I were you I might extract all the LoanTransactionDetails things into its own template. Like this:

        <xsl:apply-templates select="LoanTransactionDetails"/><br>

And then the template might be like this:

  <xsl:template match="LoanTransactionDetails">
    <soap:LoanTransactionDetails>
      <xsl:if test="procFile != ''">
        <soap:procFile><xsl:value-of select="procFile"/></soap:procFile>
      </xsl:if>
       ...
    </soap:LoanTransactionDetails>

  </xsl:template>

In my experience, XSL can be a challenge. You might want to try an interactive editor, like this one: https://xslttest.appspot.com/

(No affiliation)

View solution in original post

5 REPLIES 5

To help us help you, could you please do these things?

  • Explain in a few sentences (more than one) , what problem you are confronting.
  • post, in a code panel, your XSL policy configuration. Eg,

    <XSL name='XSL-MyPolicy'>
      <Source>something</Source>
      <OutputVariable>somethingElse</OutputVariable>
      <ResourceURL>xsl://mysheet.xsl</ResourceURL>
      <!--
          Parameters are optional. reference them in the XSL as:
          <xsl:param name="pwd" select="''"/>
          <xsl:param name="converted" select="''"/>
      -->
      <Parameters ignoreUnresolvedVariables='true'>
        <Parameter name='additional' ref='additional'/>
      </Parameters>
    </XSL>
    	
  • post in a code panel, your XSLT sheet. (Similar example)
  • post the inbound XML
  • give an example of the outbound XML you are hoping to generate. Another code panel.

There's a nice "code" button in the message editor that will allow you to include the specific different things.

I am not sure what the JSON payload has to do with the XSL. If you could explain that a little, that will help clarify, and enable us to better answer your questions!

Hi. I am taking a JSON payload - converting to xml and then creating a Soap envelope payload before sending to backend and then converting response back to JSON. I think I was incorrectly using 'root' and 'value of select' in populating SOAP envelope. I made updates but I am currently running into errors on back end when a field does not have a value in SOAP envelope. These values are optional as noted. Is there an option to set to a null value or default? I'm not sure how to handle sending only fields with values - I am sending all SOAP envelope fields whether populated or not.

I am currently running into errors on back end when a field does not have a value in SOAP envelope. These values are optional as noted. Is there an option to set to a null value or default?

I think so? You can parameterize your XSL sheet in the policy, and then set default values.

Like this:

<XSL name='XSL-1'>
  <Source>outboundMessageTemplate</Source>
  <OutputVariable>transformedContent</OutputVariable>
  <ResourceURL>xsl://sheet.xsl</ResourceURL>
  <!--
      Parameters are optional. reference them in the XSL as:
      <xsl:param name="param1" select="''"/>
  -->
  <Parameters ignoreUnresolvedVariables='true'>
    <Parameter name='param1' ref='variable-maybe-null'>default-value</Parameter>
  </Parameters>
</XSL>

I believe you can alternatively set default values in the sheet itself, like this:

     <xsl:param name="param1" select="'default-value'"/>

I'm not sure how to handle sending only fields with values - I am sending all SOAP envelope fields whether populated or not.

Yes, you'd need to include conditionals in your XSL to either include the elements or not, depending on the value of the parameter.

Hi - I thought I shared my details also in last post. See my XSL policy and sheet...I updated Ignore unresolved to true...But my sheet (sample - very large) is referring to values that are optional - wondering if I can incorporate your last suggestion...

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<XSL async="false" continueOnError="false" enabled="true" name="XSLTransform-PostPNCTransactionFile">
    <DisplayName>XSLTransform-PostPNCTransactionFile</DisplayName>
    <Properties/>
    <Source>sourceXmlContent</Source>
    <ResourceURL>xsl://Script-1.xslt</ResourceURL>
    <OutputVariable>PostPNCTransactionFileSoapPayload</OutputVariable>
    <!-- provide parameters to the XSL sheet -->
    <Parameters ignoreUnresolvedVariables="true">
        <Parameter name="pmtusername" ref="private.abs.v1.pmtusername"/>
        <Parameter name="pmtpassword" ref="private.abs.v1.pmtpassword"/>
    </Parameters>
</XSL>
The XSL?
 <soapenv:Body>
     <soap:postPNCTransactionFileRequest>
         <soap:IdentifierType>
            <!--Optional:-->
            <soap:demo><xsl:value-of select="postPNCTransactionFileRequest/IdentifierType/demo"/></soap:demo>
            <soap:appID><xsl:value-of select="postPNCTransactionFileRequest/IdentifierType/appID"/></soap:appID>
            <soap:messageID><xsl:value-of select="postPNCTransactionFileRequest/IdentifierType/messageID"/></soap:messageID>
         </soap:IdentifierType>
         <!--Zero or more repetitions:-->
          <soap:PNCTransactionFile>
          <xsl:for-each select="postPNCTransactionFileRequest/PNCTransactionFile">
            <!--You may enter the following 41 items in any order-->
            <!--Optional:-->
            <soap:ObtainObjectLocks>
               <!--Optional:-->
               <soap:PortfolioID><xsl:value-of select="ObtainObjectLocks/PortfolioID"/></soap:PortfolioID>
               <!--Optional:-->
               <soap:CANumber><xsl:value-of select="ObtainObjectLocks/CANumber"/></soap:CANumber>
               <!--Optional:-->
               <soap:LoanNumber><xsl:value-of select="ObtainObjectLocks/LoanNumber"/></soap:LoanNumber>
               <!--Optional:-->
               <soap:RequestAction><xsl:value-of select="ObtainObjectLocks/RequestAction"/></soap:RequestAction>
               <!--Optional:-->
               <soap:LockRetryWaitDef><xsl:value-of select="ObtainObjectLocks/LockRetryWaitDef"/></soap:LockRetryWaitDef>
            </soap:ObtainObjectLocks>
            <!--Optional:-->
            <soap:LoanTransactionDetails>
               <!--Optional:-->
               <soap:procFile><xsl:value-of select="LoanTransactionDetails/procFile"/></soap:procFile>
               <!--Optional:-->
               <soap:postingOrder><xsl:value-of select="LoanTransactionDetails/postingOrder"/></soap:postingOrder>
               <!--Optional:-->
               <soap:inputUnit><xsl:value-of select="LoanTransactionDetails/inputUnit"/></soap:inputUnit>
               <!--Optional:-->
               <soap:outputUnit><xsl:value-of select="LoanTransactionDetails/outputUnit"/></soap:outputUnit>
               <!--Optional:-->
               <soap:portfolio><xsl:value-of select="LoanTransactionDetails/portfolio"/></soap:portfolio>
               <!--Optional:-->
               <soap:obligtnNo><xsl:value-of select="LoanTransactionDetails/obligtnNo"/></soap:obligtnNo>
               <!--Optional:-->
               <soap:ownerId><xsl:value-of select="LoanTransactionDetails/ownerId"/></soap:ownerId>
               <!--Optional:-->
               <soap:sequence><xsl:value-of select="LoanTransactionDetails/sequence"/></soap:sequence>

Hi Frank

I think you can get what you want with a series of xsl:if elements.

If I were you I might extract all the LoanTransactionDetails things into its own template. Like this:

        <xsl:apply-templates select="LoanTransactionDetails"/><br>

And then the template might be like this:

  <xsl:template match="LoanTransactionDetails">
    <soap:LoanTransactionDetails>
      <xsl:if test="procFile != ''">
        <soap:procFile><xsl:value-of select="procFile"/></soap:procFile>
      </xsl:if>
       ...
    </soap:LoanTransactionDetails>

  </xsl:template>

In my experience, XSL can be a challenge. You might want to try an interactive editor, like this one: https://xslttest.appspot.com/

(No affiliation)