?
Solved

Incrementing a variable value in XSL and storing in hidden control

Posted on 2003-03-26
7
Medium Priority
?
750 Views
Last Modified: 2012-05-04
Dear Experts,

I have a requirement wherein a variable has to be incremented based on a condition and store the result in a hidden control.  To put in simple VB flow...

Dim x as integer
x=0
While(condition is true)
   If (1 < 2) then
      x=x+1
   End if
Wend

And finally,
<Store the value of X in a hidden control>

Can I have the equivalent code in XSL please?

<xsl:variable name="x">0</xsl:variable>
<xsl:for loop>
    <xsl:if condition>
       <Increment the value here>
    </xsl:if>
</xsl:for>
<!-- storing in a hidden control-->
<input type="hidden" name="xyz">
  <xsl:attribute name="value"><xsl:value-of select="$VariableName"/></xsl:attribute>
</input>

Well, I am aware that variable value, once assigned cannot be modified in XSL.  But, I vaguely know that it can achieved using parameters.  Please help me to solve this.

Any help on this would be greatly appreciated.

Thanks in advance but points will be awarded after solving the problem.

Cheers,
0
Comment
Question by:haibala
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
7 Comments
 
LVL 14

Expert Comment

by:avner
ID: 8211000
No.
In XSL you cannot change a variable.
For the part of the incrementation you will have to change the value of a variable, this cannot be done in XSL.

0
 

Author Comment

by:haibala
ID: 8215308
I agree, its not possible with variables in XSL. Is there any other way?  Can we do it with parameters?  If yes, I would like to know the syntax.

Thanks.
0
 
LVL 14

Expert Comment

by:avner
ID: 8215747
Try to look at this approach, the allows you to loop a certain template for few times, You you can set the start-val and end-val dynamically :


Try this approach :
<!-- put this in an existing template -->
  <xsl:call-template name="loop">
 <xsl:with-param name="start-val" select="'1'"/>
 <xsl:with-param name="end-val" select="'10'"/>
</xsl:call-template>


<!-- loops from $start-val to $end-val with a step value of
  $increment
-->
<xsl:template name="loop">
<xsl:param name="start-val" select="'0'"/>
<xsl:param name="end-val" select="'0'"/>
<xsl:param name="increment" select="'1'"/>


<xsl:if test="$start-val <= $end-val">

       <!-- do stuff here, i just print out the number -->
       VALUE:    <xsl:value-of select="$start-val"/>

 <!-- recurse -->
 <xsl:call-template name="loop">
   <xsl:with-param name="start-val" select="$start-val + $increment"/>
   <xsl:with-param name="increment" select="$increment"/>
   <xsl:with-param name="end-val" select="$end-val"/>
 </xsl:call-template>
</xsl:if>
</xsl:template>
</xsl:stylesheet>


0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Expert Comment

by:xsl-lsx
ID: 8218677
There is way keeps it simple:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt">

  <msxsl:script language="VBScript"
    implements-prefix="user"><![CDATA[

     numb=0
         
     Function Count()
          numb = numb + 1
          Count = numb
     End Function

  ]]></msxsl:script>


 <xsl:template match="input[whatever]">
    <xsl:for-each select="whatever">
     <xsl:if test="@hidden">
        <input type="hidden" name="xyz" value="{user:Count()}"/>
     </xsl:if>
    </xsl:for-each>
  </xsl:template>

</xsl:stylesheet>

0
 
LVL 1

Accepted Solution

by:
xsl-lsx earned 1500 total points
ID: 8218823
The following does it without param thus simple:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"

xmlns:user="http://yourname.com/yourtask"

xmlns:msxsl="urn:schemas-microsoft-com:xslt">

 <msxsl:script language="VBScript"
   implements-prefix="user"><![CDATA[

    numb=0
         
    Function Count()
         numb = numb + 1
         Count = numb
    End Function

 ]]></msxsl:script>


<xsl:template match="input[whatever]">
   <xsl:for-each select="whatever">
    <xsl:if test="@hidden">
       <input type="hidden" name="xyz" value="{user:Count()}"/>
    </xsl:if>
   </xsl:for-each>
 </xsl:template>

</xsl:stylesheet>
0
 
LVL 1

Expert Comment

by:xsl-lsx
ID: 8219398
XSL has immutable variables, which means the variable must receive their perpetual value on its creation and there after never be changed.  The param is a variable, on the stack. That is, they must be given a value on the call but never change during the call.  Thus, recursion of routines allows the programmer to pass a new value (i.e. incremented) to the next call.  Recursion is very useful for many problems with trees, HOWEVER, not universally applicable to many procedural problems as you have requested in using a for-loop.   Perhaps your problem can become recursive thus applicable.
0
 

Author Comment

by:haibala
ID: 11971959
Thanks very much for all the inputs
0

Featured Post

The Orion Papers

Are you interested in becoming an AWS Certified Solutions Architect?

Discover a new interactive way of training for the exam.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The Client Need Led Us to RSS I recently had an investment company ask me how they might notify their constituents about their newsworthy publications.  Probably you would think "Facebook" or "Twitter" but this is an interesting client.  Their cons…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Suggested Courses
Course of the Month8 days, 16 hours left to enroll

764 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question