Re: Change the value of global variables/params ??

Subject: Re: Change the value of global variables/params ??
From: David Carlisle <davidc@xxxxxxxxx>
Date: Wed, 8 Dec 1999 15:32:11 GMT

<xsl:if test="$last_type != .//ITEMTYPE">    <!-- test variable -->

                 <!-- update the last_type variable -->
                 <xsl:variable name="last_type" select=".//ITEMTYPE"/>        <!-- change variable -->

                <!-- output the new type -->
                <H1><xsl:value-of select=".//ITEMTYPE"/></H1>

Note that you are using an old version of the namespace, I had to change
<xsl:stylesheet xmlns:xsl="";
for xt (also some characters seem to have been lost from long lines)

But your problem is not due to the restrictions that were added to
prevent `shadowing' ie redecalring a variable in the same scope.
They are simply one of scope: the scope of a variable binding is the
surrrounding element, so the scope of that setting of last_type ends at
the </xsl:if>

The archives of this list, and the faq, have several examples showing
how you can do grouping in xsl.

Since I got this far I'll include yet another example at the
end. You'll notice it doesn't use variables at all.


<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="";>

 <xsl:output method="html"/>

 <xsl:template match="/">


        <!-- initialize our changing variable -->
       <xsl:variable name="last_type" select="'none'"
/>                                <!-- initialize variable -->

       <!-- for each item -->
       <xsl:for-each select="//ITEMTYPE[not(. = following::ITEMTYPE)]">
           <H1><xsl:value-of select="."/></H1>
         <xsl:for-each select="//ITEM[INFO/INFOTYPE/ITEMTYPE=current()]">
          <xsl:sort select="NAME"/>
           <P><xsl:value-of select="NAME"/></P>



bash-2.01$ xt pl.xml pl.xsl

 XSL-List info and archive:

Current Thread