[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: Choose-When-Otherwise Nesting Problem

Subject: RE: Choose-When-Otherwise Nesting Problem
From: "Diamond, Jason" <Jason.Diamond@xxxxxxx>
Date: Wed, 21 Feb 2001 12:06:11 -0600
xsl when null
Hi, Scott.

It's hard to see the problem without a sample source document. From your
description and the stylesheet, though, I'm guessing that the
alertDefinition elements always contain a MaxAmount element and a MinAmount
element. A string value of 'null' in either of those elements indicates that
it should be ignored. Is this correct?

Your choose/when/otherwise construct is like an if/else if/else construct.
Only one of them is getting evaluated. The first one that tests true, wins.
If the MaxAmount element does not contain 'null', that branch is "executed"
and the second when branch and the otherwise branch are ignored.

So, if I understand you correctly, I would probably change your choose
elements to this:

<xsl:choose>
  <xsl:when test="MaxAmount != 'null' or MinAmount != 'null'">
    <xsl:if test="MaxAmount != 'null'">
      &gt; <xsl:value-of select="MaxAmount"/>
    </xsl:if>  
    <xsl:if test="MinAmount != 'null'">
      &lt; <xsl:value-of select="MinAmount"/>
    </xsl:if>  
  </xsl:when>
  <xsl:otherwise>Any Change</xsl:otherwise>
</xsl:choose>

Hope this helps,
Jason.

-----Original Message-----
From: Scott Downie [mailto:sdownie@xxxxxxxxxxxxxxxxxxxx]
Sent: Wednesday, February 21, 2001 8:58 AM
To: XSL-List@xxxxxxxxxxxxxxxxxxxxxx
Subject:  Choose-When-Otherwise Nesting Problem


Hello! We're diving into XSLT and climbing the learning curve.

At the moment, we're trying to become familiar with how to nest XSL
commands. In
the example I've attached below, we want to take an incoming stream of XML
and
display text depending upon what the incoming MaxAmount and MinAmount values
are. If a particular alert is associated with a MaxAmount or a MinAmount, we
want to display it. If both MaxAmount and MinAmount are null, we want to
display
"Any Change". This process is repeated for all the incoming alerts with the
output format being altered (by the outermost choose condition) to display
alternating background colors in the output list.

When we actually try this, the very first MaxAmount or MinAmount is
displayed.
But if the first value is a MaxAmount (for example), no subsequent
MinAmounts
will appear. By the same token, if the first value is a MinAmount, no
MaxAmounts
will appear. And even if all of the MaxAmount and MinAmount input is null,
the
choose statement will never make it down to the otherwise branch that should
display "Any Change".

We must be nesting these commands in the wrong order, causing the process to
'stick' on the first MaxAmount or MinAmount. But we don't see a clear
solution.

Any help would be appreciated.

Thanks!

Scott
========================================================================
<table>
<xsl:for-each select="transaction/alertDefinitionGroup/alertDefinition">
  <xsl:choose>
    <xsl:when test="position() mod 2> 0">
      <TR>
        <TD>
          <xsl:choose>
            <xsl:when test="MaxAmount!='null'">
              &gt; $<xsl:value-of select="MaxAmount" />
            </xsl:when>
            <xsl:when test="MinAmount!='null'">
              &lt; $<xsl:value-of select="MinAmount" />
            </xsl:when>
            <xsl:otherwise>Any Change</xsl:otherwise>
          </xsl:choose>
        </TD>
      </TR>
    </xsl:when>
    <xsl:otherwise>
      <TR>
        <TD>
          <xsl:choose>
            <xsl:when test="MaxAmount!='null'">
              &gt; $<xsl:value-of select="MaxAmount" />
            </xsl:when>
            <xsl:when test="MinAmount!='null'">
              &lt; $<xsl:value-of select="MinAmount" />
            </xsl:when>
            <xsl:otherwise>Any Change</xsl:otherwise>
          </xsl:choose>
        </TD>
      </TR>
    </xsl:otherwise>
  </xsl:choose>
</xsl:for-each>
</table>


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.