2 Replies Latest reply: Apr 1, 2014 1:33 PM by Yogi RSS

    default value for an attribute in Transform Activity

    Yogi

      Hello,

       

      I have following xml element in the source and would like to map to an element in the target.

      Whenever there is no node in the source, I want to default it to a string "None"

       

      --------------------------Source XML----------------------------------------------

       

      <Instructions  InstructionType="Gen">Some Message</Instructions>

      <Instructions  InstructionType="Test">Some Other Message</Instructions>

       

      ---------------------------Transformation XSL--------------------------------------

       

       

      <xsl:if test='/ns1:OrderResponse/ns1:OrderResponseBody/ns1:OrderResponseProperties/ns1:SpecialInstructions/@InstructionType = "Gen"'>

                <xsl:choose>

                  <xsl:when test='/ns1:OrderResponse/ns1:OrderResponseBody/ns1:OrderResponseProperties/ns1:SpecialInstructions[@InstructionType = "Gen"] != ""'>

                    <ns0:siGen>

                      <xsl:value-of select='substring(/ns1:OrderResponse/ns1:OrderResponseBody/ns1:OrderResponseProperties/ns1:SpecialInstructions[@InstructionType = "Gen"],1.0,199.0)'/>

                    </ns0:siGen>

                  </xsl:when>

                  <xsl:when test="not(/ns1:OrderResponse/ns1:OrderResponseBody/ns1:OrderResponseProperties/ns1:SpecialInstructions[@InstructionType = 'General'])">

                    <ns0:siGen>

                      <xsl:text disable-output-escaping="no">None</xsl:text>

                    </ns0:siGen>

                  </xsl:when>

                  <xsl:otherwise>

                    <ns0:siGen>

                      <xsl:text disable-output-escaping="no">None</xsl:text>

                    </ns0:siGen>

                  </xsl:otherwise>

                </xsl:choose>

              </xsl:if>

       

      ---------------------------------------------Issue-------------------------------------------------------------

      When the source xml doesn't have the the node at all as shown below (commented), I cannot default the value "None" to the target element "ns0:siGen"

       

      <!--Instructions  InstructionType="Gen">Some Message</Instructions-->

      <Instructions  InstructionType="Test">Some Other Message</Instructions>

       

       

      Please advise.

       

      Thanks

      Yogi

        • 1. Re: default value for an attribute in Transform Activity
          Eric Elzinga

          shouldn't you first test on

           

          <xsl:if test='/ns1:OrderResponse/ns1:OrderResponseBody/ns1:OrderResponseProperties/ns1:SpecialInstructions


          to see if the element is there...if not..then you can create the None element.


          and when the element is there...you create another choose if/then in that statement?


          <if>

               <choose>

                    <when>

                     <when>

               </choose>

          <if not()>

            <none element>

          </if>


          something like that?


          if not..then maybe i misunderstood your problem

          • 2. Re: default value for an attribute in Transform Activity
            Yogi

            Yes Eric, you are right...it is because of the if condition:

             

            I found a better way to get it done on other forums:

             

            <xsl:variable name="gen"

                          select="ns1:OrderResponse/ns1:OrderResponseBody/ns1:OrderResponseProperties/ns1:Instructions[@InstructionType = 'Gen']" />

             

            <ns0:siGen>
              
            <xsl:choose>
              
            <xsl:when test="$gen != ''"><xsl:value-of select="$gen" /></xsl:when>
              
            <xsl:otherwise>None</xsl:otherwise>
              
            </xsl:choose>
            <ns0:siGen>



            Thanks

            Yogi