XSLT variable/param question

Discussion in 'XML' started by darel.finkbeiner@gmail.com, Jan 10, 2007.

  1. Guest

    I want to do this:

    <xsl:template>
    <xsl:choose>
    <xsl:when>
    Calculate a value.
    <xsl:eek:therwise>
    Calculate a value differently
    </xsl:choose>
    Use the value I calculated in a couple of different places
    </xsl:template>

    I can't wrap my head around how to do this. I'm desperate to do this
    whole thing in XSLT, but I'm despairing that it may just not be
    possible.

    Is there a solution that would accomplish something like this?
    , Jan 10, 2007
    #1
    1. Advertising

  2. The trick that most beginners miss is that you need to turn this inside
    out -- since XSL variables are single-assignment, you need to think in
    terms of computing a conditional value rather than conditionally
    computing a value. For example:

    <xsl:variable name="foo">
    <xsl:choose>
    <xsl:when>
    Calculate a value.
    <xsl:eek:therwise>
    Calculate a value differently
    </xsl:choose>
    </xsl:variable>

    rather than trying to do separate variable assignments in the two
    branches of the choose.

    --
    Joe Kesselman / Beware the fury of a patient man. -- John Dryden
    Joseph Kesselman, Jan 10, 2007
    #2
    1. Advertising

  3. That is genius.

    I can't thank you enough. That helps me not only in this current
    situation, but helps me understand XSLT even better. I appreciate it.


    Joseph Kesselman wrote:
    > The trick that most beginners miss is that you need to turn this inside
    > out -- since XSL variables are single-assignment, you need to think in
    > terms of computing a conditional value rather than conditionally
    > computing a value. For example:
    >
    > <xsl:variable name="foo">
    > <xsl:choose>
    > <xsl:when>
    > Calculate a value.
    > <xsl:eek:therwise>
    > Calculate a value differently
    > </xsl:choose>
    > </xsl:variable>
    >
    > rather than trying to do separate variable assignments in the two
    > branches of the choose.
    >
    > --
    > Joe Kesselman / Beware the fury of a patient man. -- John Dryden
    Darel Finkbeiner, Jan 11, 2007
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Geathaa
    Replies:
    2
    Views:
    681
    Geathaa
    Jul 30, 2003
  2. philips
    Replies:
    2
    Views:
    662
    philips
    Jul 17, 2004
  3. =?ISO-8859-2?Q?fr=EAdzel?=

    [xslt] value of a node (name given by param)

    =?ISO-8859-2?Q?fr=EAdzel?=, Jul 3, 2006, in forum: XML
    Replies:
    1
    Views:
    728
    Martin Honnen
    Jul 3, 2006
  4. ectoplasm
    Replies:
    12
    Views:
    624
    Zorro
    Jul 28, 2005
  5. Dave
    Replies:
    5
    Views:
    619
    John Bokma
    Apr 26, 2011
Loading...

Share This Page