1

I have a question about variables in XSL. I am not so clear about the variables concept.

I am creating a variables in xsl file as:

<xsl:variable name="vars"></xsl:variable>

Then in a for each loop, in every iteration i want to add one node to existing variables such as

<xsl:for-each select="...">
<vars><var>A</var></vars>
</xsl:for-each>

Should I go with variables in order to achieve this? If yes, how can I add new nodes to existing variable..

I can only operate in XSL file, no permission to access or modify xml, xsd.

Thank You

2
  • To add to what others have said, if you tell us what the input and output of your transformation look like (and if necessary, how they relate) - that is, if you describe your transformation as a function - then we should be able to show how you need to go about coding it in a non-procedural way. Commented Dec 7, 2011 at 8:46
  • Hello Michael, i posted related question here stackoverflow.com/questions/8424720/… thanks for you help. Commented Dec 8, 2011 at 0:39

2 Answers 2

2

XSLT is a functional language. This, among other things means that variables, once defined are immutable (cannot be changed).

Any problem that can be solved with an imperative solution can also be solved not only in XSLT but in any functional programming language -- probably in very similar ways. In most cases efficient functional solutions exist and can be used.

I would greatly recommend reading a good book on functional programming -- one as "Haskell in the real world". Not only as general interest, but because in the coming XPath 3.0 / XSLT 3.0 and XQuery 3.0 functions are first-class-citizens (higher order functions) and functions like fold-left(), fold-right() and map() are standard in XPath 3.0.

Please, specify your problem precisely and many people will be able to provide an XSLT solution.

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

Comments

1

Variables in XSLT are immutable; they cannot be modified. (They must also be declared and initialized in one step.)

It almost looks like you're trying to build an output structure. Can you output that result directly in the loop? If not, you'll need to rethink your approach.

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.