This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Programming without Assignment Statements


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]