This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Programming without Assignment Statements
- To: XSL-List at lists dot mulberrytech dot com
- Subject: [xsl] Programming without Assignment Statements
- From: Dan dot Diebolt at etasinc dot com
- Date: Fri, 5 Jan 2001 08:41:32 -0500
- Reply-To: xsl-list at lists dot mulberrytech dot com
I am reading XSLT Programmer's Reference by Michael Kay and he
has a discussion on the topic "Programming without Assignment Statements"
The following example is offered (p551) to demonstrate the paradigm shift
from procedural programming to functional programming
int x;
if (zeroBased) {
x=0;
} else {
x=1;
}
<xsl:variable name="x">
<xsl:choose>
<xsl:when test="$zeroBased"> 0 </xsl:when>
<xsl:otherwise> 1 </xsl:otherwise>
</xsl:choose>
</xsl:variable>
How would the example above be extended to XSLT using an if statement with more
complex then and else bodies such as below?
int x,y;
if (zeroBased) {
x=0;
y=3.14159;
} else {
x=1;
y=2.71828;
}
The following seems verbose, inefficient and impractical:
<xsl:variable name="x">
<xsl:choose>
<xsl:when test="$zeroBased"> 0 </xsl:when>
<xsl:otherwise> 1 </xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:variable name="y">
<xsl:choose>
<xsl:when test="$zeroBased"> 3.14159 </xsl:when>
<xsl:otherwise> 2.71828 </xsl:otherwise>
</xsl:choose>
</xsl:variable>
Please cc a response direct to me as I am on digest. Thanks in advance.
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list