user1847132
user1847132

Reputation: 11

how to reassign value to a variable in xslt

Here I am trying to run a single loop that searches entire xml and depending on the various conditions different variable get different values . so that it can be used later for reference.

Sample code :

<xsl:for-each select='root'>
<xsl:choose>
  <xsl:when test='first'>
     <xsl:variable name='first' select='root/first' />
  </xsl:when>
  <xsl:when test='second'>
    <xsl:variable name='namew' select='root/second' />
  </xsl:when>
  <xsl:otherwise>
    <xsl:variable name='other'>unknown</xsl:variable>
  </xsl:otherwise>
  </xsl:choose>

I Know it wont work here and i also know the reason (variable scope and constant behavior of variable) , actually i want to know the alternative solution to this problem.

Upvotes: 1

Views: 1010

Answers (1)

Dimitre Novatchev
Dimitre Novatchev

Reputation: 243459

XSLT is a functional language.

Among many things, this means that the value of a variable, once defined, cannot be changed.

If you specify a particular problem that you want to solve, many of us will be able to give you a solution in which variable's values aren't changed.

Upvotes: 1

Related Questions