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> </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 |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: Change the value of global vari, Paul Levin | Thread | Re: Change the value of global vari, Paul Levin |
Re: EZ/X Speed:, Rick Ross | Date | Re: EZ/X Speed: Rebunking Oracle's , Michael Sick |
Month |