1

I know we can't change value of variable in xslt. My question is can we first declare the variable and then set it's value later in 'if' tag i.e. assigning true() or false() according to some condition? If so how?

Is there any other way to solve this problem with keeping variable global?

Amit Singh
  • 49
  • 6
  • 1
    Duplicate of [How to change or reassign a variable in XSLT?](https://stackoverflow.com/questions/19255139/how-to-change-or-reassign-a-variable-in-xslt) – kjhughes Oct 04 '18 at 23:11
  • 1
    No. Instead of thinking how to procedurally set variables, think in terms of data flowing from input XML to output XML gated by conditions on the input XML. Then there's no need to set a flag. – kjhughes Oct 04 '18 at 23:16
  • It would be helpful if you provided an example of what you would be testing in order to set the true/false, so that we can help you determine how to achieve the true/false differently from how you are expecting to do it. Think about it declaratively, and how you can perform that test to set the boolean in an XPath or function call in the declaration of the global variable. – Mads Hansen Oct 05 '18 at 03:02

1 Answers1

1

There is no "later" in XSLT; order of execution is not defined, so time-based descriptions of the processing have no meaning. You need to think in purely functional terms: how does the value of X depend on the value of Y?

When you declare a variable, you must bind its value there and then. If you can't see how to do that in your particular case, you will need to explain your particular case and then we can show you.

Michael Kay
  • 156,231
  • 11
  • 92
  • 164