TechGeek
TechGeek

Reputation: 508

How to apply if-else on foreach loop using xslt

I have to filter/assign data from payload to xml tags based on if else condition using xslt.

I have to apply the if-else on "RIMSTS" tag, I'm using the below code to apply.But it is not working.It is throwing some invalid xslt during validation.Can someone help me with proper syntax or proper way to apply if-else in for-each.

<xsl:for-each select="message/lines">
                    <LINE_SEG>
                        <xsl:if test="not(normalize-space(costAmount)) = ''">
                        <CSTMS_CST>
                          <xsl:value-of select="normalize-space(costAmount)"/>
                        </CSTMS_CST>
                        </xsl:if>
                        <PO_CHANNEL></PO_CHANNEL>
                      <xsl:choose>
                      <xsl:when test="linestatusCd = 100">
                        <RIMSTS>OPEN</RIMSTS>
                      </xsl:when>
                      <xsl:when test="linestatusCd= 200 or 300">
                        <RIMSTS>CLOSED</RIMSTS>
                      </xsl:when>
                      </LINE_SEG>
                    </xsl:for-each>

Upvotes: 0

Views: 399

Answers (1)

Pete Kirkham
Pete Kirkham

Reputation: 49321

linestatusCd= 200 or 300

looks off, you probably meant

linestatusCd = 200 or linestatusCd = 300

you also haven't closed your <choose> element.

<xsl:for-each select="message/lines">
    <LINE_SEG>
        <xsl:if test="not(normalize-space(costAmount)) = ''">
        <CSTMS_CST>
          <xsl:value-of select="normalize-space(costAmount)"/>
        </CSTMS_CST>
        </xsl:if>
        <PO_CHANNEL></PO_CHANNEL>
      <xsl:choose>
      <xsl:when test="linestatusCd = 100">
        <RIMSTS>OPEN</RIMSTS>
      </xsl:when>
      <xsl:when test="linestatusCd = 200 or linestatusCd = 300">
        <RIMSTS>CLOSED</RIMSTS>
      </xsl:when>
      </xsl:choose>
   </LINE_SEG>
</xsl:for-each>

Upvotes: 2

Related Questions