Conditional variable assignment

Discussion in 'XML' started by Hoi Wong, Jan 6, 2009.

  1. Hoi Wong

    Hoi Wong Guest

    I was trying to conditionally define a bunch of global variable but turns
    out that I'm stuck with FAQ#27 in this page:
    http://www.dpawson.co.uk/xsl/sect2/N8090.html

    What it says is that I have to select the value inside variable definition,
    instead of assigning different values to a variable depending on the
    conditions.

    However, I have 40 variables that needs to be defined base on 3 logical
    cases (<xsl:choose>). Doing so will make my XSLT scripts unreadable and
    there's a lot of typing. Is there any other way round?

    Thanks.

    Cheers,
    Hoi
     
    Hoi Wong, Jan 6, 2009
    #1
    1. Advertising

  2. Hoi Wong wrote:
    > I was trying to conditionally define a bunch of global variable but turns
    > out that I'm stuck with FAQ#27 in this page:
    > http://www.dpawson.co.uk/xsl/sect2/N8090.html
    >
    > What it says is that I have to select the value inside variable definition,
    > instead of assigning different values to a variable depending on the
    > conditions.
    >
    > However, I have 40 variables that needs to be defined base on 3 logical
    > cases (<xsl:choose>). Doing so will make my XSLT scripts unreadable and
    > there's a lot of typing. Is there any other way round?


    I am not completely sure I understand your problem. If you want to
    define variable values based on certain conditions and you want to avoid
    repeating code then consider to put the code into a function (XSLT/XPath
    2.0) or a template (XSLT/XPath 1.0 and 2.0).


    --

    Martin Honnen
    http://JavaScript.FAQTs.com/
     
    Martin Honnen, Jan 6, 2009
    #2
    1. Advertising

  3. Hoi Wong

    Hoi Wong Guest

    FAQ#27 basically suggest breaking down <xsl:variable name="XX"
    select="someXpath"> into <xsl:variable name="XX"><xsl:value-of
    select="someXpath"></xsl:variable> and that'll make my code clumsy.

    Even worse, I just found that <xsl:value-of> converts the results to
    strings, which screws up boolean variables.

    Is there any way that I can still define a variable conditionally yet the
    result doesn't have to be converted to strings?

    Thanks.

    Cheers,
    Hoi





    "Martin Honnen" <> wrote in message
    news:4963454d$0$30233$-online.net...
    > Hoi Wong wrote:
    >> I was trying to conditionally define a bunch of global variable but turns
    >> out that I'm stuck with FAQ#27 in this page:
    >> http://www.dpawson.co.uk/xsl/sect2/N8090.html
    >>
    >> What it says is that I have to select the value inside variable
    >> definition, instead of assigning different values to a variable depending
    >> on the conditions.
    >>
    >> However, I have 40 variables that needs to be defined base on 3 logical
    >> cases (<xsl:choose>). Doing so will make my XSLT scripts unreadable and
    >> there's a lot of typing. Is there any other way round?

    >
    > I am not completely sure I understand your problem. If you want to define
    > variable values based on certain conditions and you want to avoid
    > repeating code then consider to put the code into a function (XSLT/XPath
    > 2.0) or a template (XSLT/XPath 1.0 and 2.0).
    >
    >
    > --
    >
    > Martin Honnen
    > http://JavaScript.FAQTs.com/
     
    Hoi Wong, Jan 7, 2009
    #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. itsme
    Replies:
    1
    Views:
    1,689
    Ralf Hildebrandt
    Jul 23, 2003
  2. Anand P Paralkar
    Replies:
    2
    Views:
    9,544
    Srinivasan Venkataramanan
    Aug 4, 2003
  3. Johnsy Joseph

    Conditional assignment to signals

    Johnsy Joseph, Sep 21, 2004, in forum: VHDL
    Replies:
    8
    Views:
    4,929
    Raghavendra
    Sep 24, 2004
  4. Alec S.
    Replies:
    10
    Views:
    10,315
    Alec S.
    Apr 16, 2005
  5. Josselin
    Replies:
    3
    Views:
    96
    William James
    Jan 22, 2007
Loading...

Share This Page