Subject: Re: Change the value of global variables/params ?? From: Paul Levin <plevin@xxxxxxx> Date: Wed, 08 Dec 1999 13:19:21 -0500 |
David, As a friend of mine says, "Way Cool !" I will stop using the "changing variable" "feature (bug)". Thanks, Paul David Carlisle wrote: > <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 XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: Change the value of global vari, David Carlisle | Thread | Re: Change the value of global vari, Patrice Bonhomme |
Re: xt pipeline, William Lindsey | Date | Re: Serialize DOM, David Tolpin |
Month |