xsl:variable question ?

  • 15 years ago

    Hi peeps,


    I've got an issue with xsl that i could use some help with. I'm under the impression that using the xsl:variable element might be a way to solve the issue.


    i would like my xslt from within a <xsl:for-each> element to parse through some nodes in a xml and to set a xsl:variable element if a condition is satisfied, Such that i could do some other stuff outside the <xsl:for-each> once the for loop is over with.


    i was wondering if this would work ?


    <xsl:variable name="trial"/> <!--an empty global variable -->


    <xsl:for-each select="some nodes here">
     <xsl:if test="if some condition is satisfied among any of the nodes">
        <!-- does this refer to the global variable "trial" ? -->
        <!-- I would like to add content to the global variable ? -->
         <xsl:variable name=trial>
              <xsl:value-of select="'yes'">
          </xsl:variable>
      </xsl:if>
    </xsl:for-each>


    <!-- seems like the global trial is still empty -->
    <xsl:if test="$trial='yes'">
    ...do some stuff ...
    </xsl:if>


    as i have commented in the xsl the global variable is shadowed while inside the for loop, and is still empty once accessed outside the for loop. Is there a way i could solve this issue ? perhaps using some other xsl element ?


    Any help would be appreciated ..


    Thanks.

Post a reply

No one has replied yet! Why not be the first?

Sign in or Join us (it's free).

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“Before software should be reusable, it should be usable.” - Ralph Johnson