[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

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
bash global variables

<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>
</xsl:if>

Note that you are using an old version of the namespace, I had to change
to
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  version="1.0">
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.

David


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

 <xsl:output method="html"/>

 <xsl:template match="/">
     <HTML>

     <BODY>

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

       <!-- for each item -->
       <xsl:for-each select="//ITEMTYPE[not(. = following::ITEMTYPE)]">
          <xsl:sort/>
           <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>
        
       </xsl:for-each>
       </xsl:for-each>

     </BODY>
     </HTML>
 </xsl:template>

</xsl:stylesheet>



bash-2.01$ xt pl.xml pl.xsl
<HTML>
<BODY>
<H1>TYPE1</H1>
<P>Name1</P>
<P>Name2</P>
<H1>TYPE2</H1>
<P>Name3</P>
<P>Name4</P>
</BODY>
</HTML>
bash-2.01$ 


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.