4 Replies Latest reply: May 3, 2012 8:31 AM by 905160 RSS

    any idea on below xml format

    905160
      I am trying to generate .xsl based on .xml file which is a xsd dump for my .xsl

      Example 1

      <Address>
      -<Street2> <xsl:value-of select="Payer/Address/AddressLine2"/> </Street2>
      </Address>

      If there is no value in Payer/Address/AddressLine2 then currently my output is coming as

      <Address><Street2/></Address>

      but I dont want to show this complete tag



      Example 2


      <Address>
      -<Street1> <xsl:value-of select="Payer/Address/AddressLine2"/> </Street1>
      -<Street2> <xsl:value-of select="Payer/Address/AddressLine2"/> </Street2>
      </Address>


      suppose Street1 has a value and street2 does not have a value then I need to show my output as


      <Address>
      <Street1> xyz</Street1>
      </Address>

      Can some one tell me how to handle this situation



      Thanks
        • 1. Re: any idea on below xml format
          odie_63
          You can do it with an <xsl:if> element, e.g. :
          <Address>
          
            <xsl:if test="normalize-space(Payer/Address/AddressLine1)">
              <Street1><xsl:value-of select="Payer/Address/AddressLine1"/></Street1>
            </xsl:if>
            
            <xsl:if test="normalize-space(Payer/Address/AddressLine2)">
              <Street2><xsl:value-of select="Payer/Address/AddressLine2"/></Street2>
            </xsl:if>
            
          </Address>
          {code}                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            
          • 2. Re: any idea on below xml format
            905160
            Hi, Thank you very much, It was really helpful.

            Edited by: 902157 on May 2, 2012 7:05 AM
            • 3. Re: any idea on below xml format
              odie_63
              Well, it's not that hard to enclose the whole thing in another xsl:if element :
              <xsl:if test="Payer/Address[normalize-space(AddressLine1) or normalize-space(AddressLine2)]">
              
               <Address>
              
                <testhead>IN</testhead>
              
                <xsl:if test="normalize-space(Payer/Address/AddressLine1)">
                  <Street1><xsl:value-of select="Payer/Address/AddressLine1"/></Street1>
                </xsl:if>
                  
                <xsl:if test="normalize-space(Payer/Address/AddressLine2)">
                  <Street2><xsl:value-of select="Payer/Address/AddressLine2"/></Street2>
                </xsl:if>
                 
               </Address>
              
              </xsl:if>
              {code}
              
              I don't know how this part fits in the stylesheet but you can also make it a template and call/apply it where appropriate : 
              {code:xml}
              <xsl:template match="Payer/Address[normalize-space(AddressLine1) or normalize-space(AddressLine2)]">
              
               <Address>
              
                <testhead>IN</testhead>
              
                <xsl:if test="normalize-space(AddressLine1)">
                  <Street1><xsl:value-of select="AddressLine1"/></Street1>
                </xsl:if>
                  
                <xsl:if test="normalize-space(AddressLine2)">
                  <Street2><xsl:value-of select="AddressLine2"/></Street2>
                </xsl:if>
                 
               </Address>
              
              </xsl:template>
              {code}                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    
              • 4. Re: any idea on below xml format
                905160
                Thanks, I tried the similar way...it worked...