0

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>
1
  • Please provide a minimal reproducible example. On the face of it, you are missing a closing </xsl:choose> tag. -- P.S. If you're getting an error message, the smart thing to do is to reproduce it verbatim. Commented Mar 13, 2020 at 17:08

1 Answer 1

2
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>
Sign up to request clarification or add additional context in comments.

3 Comments

I tried the above solution. Which is working. For another case I'm applying otherwise for else condition. It was not working for otherwise.Can I know the proper way to use when and otherwise in for-each.
Yes, you can know the proper way: there are many sources of information (e.g. books). We're not here to write new books and tutorials just for you, we're here to help you when you've read the books and still get stuck. If your first question has been answered and you have another question, then please raise it as a new question, saying specifically what you did and how it failed.
Also, please tag your question with a specific XSLT version; you've used both 1.0 and 2.0 tags so we don't know which version you are using.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.