Ataman
Ataman

Reputation: 2590

Adding new nodes to existing variable XSL

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

Upvotes: 1

Views: 2003

Answers (2)

Dimitre Novatchev
Dimitre Novatchev

Reputation: 243449

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.

Upvotes: 2

Wayne
Wayne

Reputation: 60414

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.

Upvotes: 1

Related Questions