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?

3
  • 1
    Duplicate of How to change or reassign a variable in XSLT? Commented Oct 4, 2018 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. Commented Oct 4, 2018 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. Commented Oct 5, 2018 at 3:02

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.