RE: [xsl] Global variable problem

Subject: RE: [xsl] Global variable problem
From: "Michael Kay" <mhk@xxxxxxxxx>
Date: Wed, 12 May 2004 14:06:17 +0100
You are much more likely to get a solution to your problem if you take the
trouble to remove the irrelevant material from your stylesheet and source
XML, and add some indentation to make it readable. Try to get both the
stylesheet and the source document to fit on one screenful of text. People
on this list like to help, but they are busy.

Michael Kay

> -----Original Message-----
> From: Angeshwar Deepak [mailto:angeshwar@xxxxxxxxx] 
> Sent: 12 May 2004 12:59
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject: [xsl] Global variable problem
> 
> Hi,
> 
> I have a problem. I have declared a global variable
> in the <xsl:stylesheet tag.
> 
> I am using a jscript function which is called from a
> for-each loop. The function which returns a value is
> stored in xsl variable. I want to use this variable in
> another for-each loop.
> 
> (Note that the value is dynamic ie only after the end
> of the loop i get the final value)-so i need the final
> value after the end of loop.
> 
> I read the previous replies concerning this problem
> but could not get any solution.
> 
> My xslt file:
> 
> <?xml version="1.0"?>
> <xsl:stylesheet version="1.0"
> xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
>   xmlns:msxsl="urn:schemas-microsoft-com:xslt"
>  xmlns:user="http://";>
> <xsl:param name="js_var" />
> <xsl:variable name="global"/>
> 
> <msxsl:script language="JScript"
> implements-prefix="user">
>  <![CDATA[
>  
> /////////////////Function to count number of
> nodes////////////////////
>  var incr=0;
>  function count() {
>       incr++;
>       return incr;
>    }
> 
> /////////////////Function to get the package name from
> class name///////
>    function  package(getvalue)
>    {
> var i;
> var getstring=getvalue;
> var strlrn=0;
> var newarray=new Array();
> var final;
> strlen=getstring.length;
> var index=getstring.lastIndexOf(".");
> for(i=0;i<index;i++)
> 	{
> 	newarray[i]=getstring.charAt(i); 
> 	}
> final=newarray.toString();
> for(i=0;i<index;i++)
> final = final.replace(',','');
> 
> return final;
> }
> 
>    function compare(getvalue2, getvalue3)
>    {
> var getstring2=getvalue2;
> var getstring3=getvalue3;
> var final1;
> var strlen1;var strlen2;
> 
> strlen1=getstring3.length;  //lenghth of package name
> 
> strlen1=strlen1*2-1;
> var getstring4 = getstring2.match(getstring3) ;
> 
> final1=getstring4.toString();
> 
> if(final1==getstring3)
>    return 'Class belongs to the package';
> else
>    return '';	
>    }
> 
> /////////////////Function to count number of
> Packages////////////////////
> var count_package=0 ;
> var temp1='a';
> var temp2='b';
> var cpackage;
> function countpackages(getpackagename)
>    {
> var pname=getpackagename;
> //if(pname='') count_package--;
> temp1=pname; 
> if(temp2!=temp1)
> {
> 	count_package++;
> 	temp2=temp1;
> }
>    return count_package;
>    }
>  ]]>
>  </msxsl:script>
> 
> <!--/////////////////////Start of XSLT
> coding/////////////////////////////////////-->
> <!--<xsl:param name="js_var"/>
> <xsl:variable name="global"/>-->
> 
> <xsl:template match="/">
> 
> <html>
> <head>
> <title>Findbugs Summary Report</title>
> </head>
> <body>
> 
> <h2 align="center">Findbugs Summary Report</h2>
> <xsl:for-each select = "BugCollection/BugInstance">
> 
> <xsl:variable name="classname"
> select="Class/@classname" />		
> <xsl:variable name="packagename"
> select="user:package(string($classname))"/>
> <xsl:variable name="countpackage"
> select="user:countpackages(string($packagename))"/>
> <!--<xsl:variable name="ifresult"
> select="user:compare(string($classname),
> string($packagename) )"/> -->
> <!--<h2>Result of if :<xsl:value-of
> select="$ifresult"/></h2>-->
> 
> <!--<xsl:if test='$ifresult'>-->
> <xsl:variable name="countnode" select="user:count()"/>
> 
> <h4>Package name:<xsl:value-of
> select="$packagename"/></h4>
> <h4>Package count:<xsl:value-of
> select="$countpackage"/></h4>
> <h4>Node number:<xsl:value-of select="$countnode"
> /></h4>
> 
> 
> <table border="1" cellpadding="1" cellspacing="0"
> width="65" height="25">
> 
> <h4>Class name:<xsl:value-of
> select="$classname"/></h4>
> <tr> <td> Type: </td> <td> <xsl:value-of
> select="@type"/> </td> </tr> 
> <tr> <td> Priority: </td> <td> <xsl:value-of
> select="@priority"/> </td> </tr> 
> <tr> <td> Source File: </td> <td> <xsl:value-of
> select="SourceLine/@sourcefile"/> </td> </tr>
> <tr> <td> Class Name: </td> <td> <xsl:value-of
> select="Class/@classname"/> <xsl:value-of
> select="Class" /> </td> </tr> 
> <tr> <td> Method Name: </td> <td> <xsl:value-of
> select="Method/@name"/> </td> </tr>
> <tr> <td> Start: </td> <td> <xsl:value-of
> select="Method/SourceLine/@start"/> </td> </tr>
> <tr> <td> End: </td> <td> <xsl:value-of
> select="Method/SourceLine/@end"/> </td> </tr>
> 
> </table>
> 
> <h2>Package count:<xsl:value-of
> select="$global"/></h2>
> <h2>Package count:<xsl:value-of
> select="$js_var"/></h2>
> <!--	</xsl:when>
> </xsl:choose>
> </xsl:for-each>-->
> 
> </xsl:for-each>
> 
> <h1>TEST</h1>
> <h2>Package count:<xsl:value-of
> select="$global"/></h2>
> 
>        </body></html>
> </xsl:template>
> </xsl:stylesheet>
> 
> 
> 
> 
> 
> Part f my XML file:
> 
> <?xml version="1.0" encoding="UTF-8"?>
> <?xml-stylesheet type="text/xsl" href="bcel-fb.xsl"?>
> <BugCollection>
>   
>   <Project filename="&lt;&lt;unnamed project&gt;&gt;">
>    
> <Jar>D:\deepak\buildProcess_2\logging\build\class</Jar>
>    
> <SrcDir>D:\deepak\buildProcess_2\logging\build\src</SrcDir>
>   
>   </Project>
>   
>   <BugInstance type="URF_UNREAD_FIELD" priority="2">
>     <Class>
> dcx.sysman.logging.SMIEntityBeanLogger</Class>
>     <Field
> classname="dcx.sysman.logging.SMIEntityBeanLogger"
> name="privateLogHandler"
> signature="Ldcx/sysman/logging/handler/SMILogHandler;"
> isStatic="false"/>
>   </BugInstance>
>   
>   <BugInstance type="UCF_USELESS_CONTROL_FLOW"
> priority="2">
>     <Class>
> dcx.sysman.logging.SMIHttpServletLogger</Class>
>     <Method
> classname="dcx.sysman.logging.SMIHttpServletLogger"
> name="log"
> signature="(JLjavax/servlet/http/HttpServletRequest;Ljava/lang
> /String;Ljava/lang/String;[Ljava/lang/Object;)V">
>       <SourceLine
> classname="dcx.sysman.logging.SMIHttpServletLogger"
> start="62" end="99" startBytecode="0"
> endBytecode="146"
> sourcefile="SMIHttpServletLogger.java"/>
>     </Method>
>     <SourceLine
> classname="dcx.sysman.logging.SMIHttpServletLogger"
> start="76" end="76" startBytecode="60"
> endBytecode="60"
> sourcefile="SMIHttpServletLogger.java"/>
>   </BugInstance>
>   
>   <BugInstance type="DM_BOOLEAN_CTOR" priority="2">
>     <Class
> classname="dcx.sysman.logging.SMILogManager"/>
>     <Method
> classname="dcx.sysman.logging.SMILogManager"
> name="checkPrefilter"
> signature="(Ljava/lang/String;J)Z">
>       <SourceLine
> classname="dcx.sysman.logging.SMILogManager"
> start="953" end="1011" startBytecode="0"
> endBytecode="424" sourcefile="SMILogManager.java"/>
>     </Method>
>     <SourceLine
> classname="dcx.sysman.logging.SMILogManager"
> start="1009" end="1009" startBytecode="415"
> endBytecode="415" sourcefile="SMILogManager.java"/>
>   </BugInstance>
>   
>   <BugInstance type="DM_BOOLEAN_CTOR" priority="2">
>     <Class
> classname="dcx.sysman.logging.SMILogManager"/>
>     <Method
> classname="dcx.sysman.logging.SMILogManager"
> name="init" signature="(Ljava/util/Properties;)V">
>       <SourceLine
> classname="dcx.sysman.logging.SMILogManager"
> start="732" end="805" startBytecode="0"
> endBytecode="441" sourcefile="SMILogManager.java"/>
>     </Method>
>     <SourceLine
> classname="dcx.sysman.logging.SMILogManager"
> start="746" end="746" startBytecode="97"
> endBytecode="97" sourcefile="SMILogManager.java"/>
>   </BugInstance>
>   
>   <BugInstance type="DM_BOOLEAN_CTOR" priority="2">
>     <Class
> classname="dcx.sysman.logging.SMILogManager"/>
>     <Method
> classname="dcx.sysman.logging.SMILogManager"
> name="setSystemProperties"
> signature="(Ljava/util/Properties;)V">
>       <SourceLine
> classname="dcx.sysman.logging.SMILogManager"
> start="204" end="240" startBytecode="0"
> endBytecode="276" sourcefile="SMILogManager.java"/>
>     </Method>
>     <SourceLine
> classname="dcx.sysman.logging.SMILogManager"
> start="214" end="214" startBytecode="68"
> endBytecode="68" sourcefile="SMILogManager.java"/>
>   </BugInstance>
>   
>   <BugInstance type="DM_STRING_CTOR" priority="2">
>     <Class
> classname="dcx.sysman.logging.SMILogManager"/>
>     <Method
> classname="dcx.sysman.logging.SMILogManager"
> name="initSystemPrefilterConfiguration"
> signature="(Ljava/util/Properties;)V">
>       <SourceLine
> classname="dcx.sysman.logging.SMILogManager"
> start="1389" end="1436" startBytecode="0"
> endBytecode="438" sourcefile="SMILogManager.java"/>
>     </Method>
>     <SourceLine
> classname="dcx.sysman.logging.SMILogManager"
> start="1397" end="1397" startBytecode="64"
> endBytecode="64" sourcefile="SMILogManager.java"/>
>   </BugInstance>
>   
>   <BugInstance type="DM_STRING_VOID_CTOR"
> priority="2">
>     <Class
> classname="dcx.sysman.logging.SMILogManager"/>
>     <Method
> classname="dcx.sysman.logging.SMILogManager"
> name="doInitFilter"
> signature="(Ljava/util/Hashtable;Ljava/lang/String;)Ldcx/sysma
n/logging/filter/SMIMessageFilter;">
>       <SourceLine
> classname="dcx.sysman.logging.SMILogManager"
> start="1281" end="1327" startBytecode="0"
> endBytecode="367" sourcefile="SMILogManager.java"/>
>     </Method>
>     <SourceLine
> classname="dcx.sysman.logging.SMILogManager"
> start="1302" end="1302" startBytecode="177"
> endBytecode="177" sourcefile="SMILogManager.java"/>
>   </BugInstance>
>   
>   <BugInstance type="DM_STRING_VOID_CTOR"
> priority="2">
>     <Class
> classname="dcx.sysman.logging.SMILogManager"/>
>     <Method
> classname="dcx.sysman.logging.SMILogManager"
> name="doInitHandler"
> signature="(Ljava/util/Hashtable;Ljava/lang/String;)Ldcx/sysma
n/logging/handler/SMIHandler;">
>       <SourceLine
> classname="dcx.sysman.logging.SMILogManager"
> start="1343" end="1381" startBytecode="0"
> endBytecode="396" sourcefile="SMILogManager.java"/>
>     </Method>
>     <SourceLine
> classname="dcx.sysman.logging.SMILogManager"
> start="1350" end="1350" startBytecode="83"
> endBytecode="83" sourcefile="SMILogManager.java"/>
>   </BugInstance>
>   
>   <BugInstance type="IS2_INCONSISTENT_SYNC"
> priority="2">
>     <Class
> classname="dcx.sysman.logging.SMILogManager"/>
>     <Field
> classname="dcx.sysman.logging.SMILogManager"
> name="groupLoggerReferences" signature="I"
> isStatic="false"/>
>     <Int value="85" role="INT_SYNC_PERCENT"/>
>     <SourceLine
> classname="dcx.sysman.logging.SMILogManager"
> start="654" end="654" startBytecode="48"
> endBytecode="48" sourcefile="SMILogManager.java"
> role="SOURCE_LINE_UNSYNC_ACCESS"/>
>   </BugInstance>
>   
>   <BugInstance type="IS2_INCONSISTENT_SYNC"
> priority="2">
>     <Class
> classname="dcx.sysman.logging.SMILogManager"/>
>     <Field
> classname="dcx.sysman.logging.SMILogManager"
> name="groupLoggers" signature="Ljava/util/Hashtable;"
> isStatic="false"/>
>     <Int value="85" role="INT_SYNC_PERCENT"/>
>     <SourceLine
> classname="dcx.sysman.logging.SMILogManager"
> start="653" end="653" startBytecode="43"
> endBytecode="43" sourcefile="SMILogManager.java"
> role="SOURCE_LINE_UNSYNC_ACCESS"/>
>   </BugInstance>
>   
>   <BugInstance type="LI_LAZY_INIT_STATIC"
> priority="1">
>     <Class
> classname="dcx.sysman.logging.SMILogManager"/>
>     <Method
> classname="dcx.sysman.logging.SMILogManager"
> name="addSMIPropertyChangeListener"
> signature="(Ljava/beans/PropertyChangeListener;)V">
>       <SourceLine
> classname="dcx.sysman.logging.SMILogManager"
> start="569" end="573" startBytecode="0"
> endBytecode="10" sourcefile="SMILogManager.java"/>
>     </Method>
>     <Field
> classname="dcx.sysman.logging.SMILogManager"
> name="propChangeSupport"
> signature="Ljava/beans/PropertyChangeSupport;"
> isStatic="true" role="FIELD_ON"/>
>     <SourceLine
> classname="dcx.sysman.logging.SMILogManager"
> start="569" end="570" startBytecode="0"
> endBytecode="16" sourcefile="SMILogManager.java"/>
>   </BugInstance>
>   
>   <BugInstance type="LI_LAZY_INIT_STATIC"
> priority="1">
>     <Class
> classname="dcx.sysman.logging.SMILogManager"/>
>     <Method
> classname="dcx.sysman.logging.SMILogManager"
> name="getGlobalLogHandler"
> signature="()Ldcx/sysman/logging/handler/SMILogHandler;">
>       <SourceLine
> classname="dcx.sysman.logging.SMILogManager"
> start="265" end="286" startBytecode="0"
> endBytecode="31" sourcefile="SMILogManager.java"/>
>     </Method>
>     <Field
> classname="dcx.sysman.logging.SMILogManager"
> name="globalLogHandler"
> signature="Ldcx/sysman/logging/handler/SMIGlobalLogHandler;"
> isStatic="true" role="FIELD_ON"/>
>     <SourceLine
> classname="dcx.sysman.logging.SMILogManager"
> start="265" end="266" startBytecode="0"
> endBytecode="13" sourcefile="SMILogManager.java"/>
>   </BugInstance>
>   
>   <BugInstance type="LI_LAZY_INIT_STATIC"
> priority="1">
>     <Class
> classname="dcx.sysman.logging.SMILogManager"/>
>     <Method
> classname="dcx.sysman.logging.SMILogManager"
> name="getSMILogManager"
> signature="()Ldcx/sysman/logging/SMILogManager;">
>       <SourceLine
> classname="dcx.sysman.logging.SMILogManager"
> start="302" end="305" startBytecode="0"
> endBytecode="7" sourcefile="SMILogManager.java"/>
>     </Method>
>     <Field
> classname="dcx.sysman.logging.SMILogManager"
> name="logManager"
> signature="Ldcx/sysman/logging/SMILogManager;"
> isStatic="true" role="FIELD_ON"/>
>     <SourceLine
> classname="dcx.sysman.logging.SMILogManager"
> start="302" end="303" startBytecode="0"
> endBytecode="13" sourcefile="SMILogManager.java"/>
>   </BugInstance>
>   
>   <BugInstance type="MS_EXPOSE_REP" priority="2">
>     <Class
> classname="dcx.sysman.logging.SMILogManager"/>
>     <Method
> classname="dcx.sysman.logging.SMILogManager"
> name="getSMIManageableObjects"
> signature="()[Ljava/lang/Object;">
>       <SourceLine
> classname="dcx.sysman.logging.SMILogManager"
> start="322" end="322" startBytecode="0"
> endBytecode="3" sourcefile="SMILogManager.java"/>
>     </Method>
>     <Field
> classname="dcx.sysman.logging.SMILogManager"
> name="manageableObjects"
> signature="[Ljava/lang/Object;" isStatic="true"/>
>     <SourceLine
> classname="dcx.sysman.logging.SMILogManager"
> start="322" end="322" startBytecode="3"
> endBytecode="3" sourcefile="SMILogManager.java"/>
>   </BugInstance>
>   
>   <BugInstance type="MS_PKGPROTECT" priority="2">
>     <Class
> classname="dcx.sysman.logging.SMILogManager"/>
>     <Field
> classname="dcx.sysman.logging.SMILogManager"
> name="emergencyHandler"
> signature="Ldcx.sysman.logging.handler.SMILogHandler;"
> isStatic="true"/>
>   </BugInstance>
>   
>   <BugInstance type="MS_PKGPROTECT" priority="2">
>     <Class
> classname="dcx.sysman.logging.SMILogManager"/>
>     <Field
> classname="dcx.sysman.logging.SMILogManager"
> name="globalLogHandler"
> signature="Ldcx.sysman.logging.handler.SMIGlobalLogHandler;"
> isStatic="true"/>
>   </BugInstance>
>   
>   <BugInstance type="DM_STRING_CTOR" priority="2">
>     <Class classname="dcx.sysman.logging.SMIMessage"/>
>     <Method classname="dcx.sysman.logging.SMIMessage"
> name="setParams" signature="([Ljava/lang/Object;)V">
>       <SourceLine
> classname="dcx.sysman.logging.SMIMessage" start="540"
> end="557" startBytecode="0" endBytecode="134"
> sourcefile="SMIMessage.java"/>
>     </Method>
>     <SourceLine
> classname="dcx.sysman.logging.SMIMessage" start="551"
> end="551" startBytecode="106" endBytecode="106"
> sourcefile="SMIMessage.java"/>
>   </BugInstance>
>   <BugInstance type="EI_EXPOSE_REP" priority="2">
>     <Class classname="dcx.sysman.logging.SMIMessage"/>
>     <Method classname="dcx.sysman.logging.SMIMessage"
> name="getProcessId" signature="()[Ljava/lang/String;">
>       <SourceLine
> classname="dcx.sysman.logging.SMIMessage" start="463"
> end="463" startBytecode="0" endBytecode="4"
> sourcefile="SMIMessage.java"/>
>     </Method>
>     <Field classname="dcx.sysman.logging.SMIMessage"
> name="processID" signature="[Ljava/lang/String;"
> isStatic="false"/>
>     <SourceLine
> classname="dcx.sysman.logging.SMIMessage" start="463"
> end="463" startBytecode="4" endBytecode="4"
> sourcefile="SMIMessage.java"/>
>   </BugInstance>
>   <BugInstance type="EI_EXPOSE_REP" priority="2">
>     <Class classname="dcx.sysman.logging.SMIMessage"/>
>     <Method classname="dcx.sysman.logging.SMIMessage"
> name="getSequenceNr" signature="()[J">
>       <SourceLine
> classname="dcx.sysman.logging.SMIMessage" start="291"
> end="291" startBytecode="0" endBytecode="4"
> sourcefile="SMIMessage.java"/>
>     </Method>
>     <Field classname="dcx.sysman.logging.SMIMessage"
> name="sequenceNr" signature="[J" isStatic="false"/>
>     <SourceLine
> classname="dcx.sysman.logging.SMIMessage" start="291"
> end="291" startBytecode="4" endBytecode="4"
> sourcefile="SMIMessage.java"/>
>   </BugInstance>
>   <BugInstance type="EI_EXPOSE_REP" priority="2">
>     <Class classname="dcx.sysman.logging.SMIMessage"/>
>     <Method classname="dcx.sysman.logging.SMIMessage"
> name="getSignature" signature="()[B">
>       <SourceLine
> classname="dcx.sysman.logging.SMIMessage" start="574"
> end="574" startBytecode="0" endBytecode="4"
> sourcefile="SMIMessage.java"/>
>     </Method>
>     <Field classname="dcx.sysman.logging.SMIMessage"
> name="signature" signature="[B" isStatic="false"/>
>     <SourceLine
> classname="dcx.sysman.logging.SMIMessage" start="574"
> end="574" startBytecode="4" endBytecode="4"
> sourcefile="SMIMessage.java"/>
>   </BugInstance>
>   <BugInstance type="UCF_USELESS_CONTROL_FLOW"
> priority="2">
>     <Class
> classname="dcx.sysman.logging.SMIPortletLogger"/>
>     <Method
> classname="dcx.sysman.logging.SMIPortletLogger"
> name="log"
> signature="(JLorg/apache/jetspeed/portlet/PortletRequest;Ljava
> /lang/String;Ljava/lang/String;[Ljava/lang/Object;)V">
>       <SourceLine
> classname="dcx.sysman.logging.SMIPortletLogger"
> start="38" end="69" startBytecode="0"
> endBytecode="145" sourcefile="SMIPortletLogger.java"/>
>     </Method>
>     <SourceLine
> classname="dcx.sysman.logging.SMIPortletLogger"
> start="62" end="62" startBytecode="133"
> endBytecode="133" sourcefile="SMIPortletLogger.java"/>
>   </BugInstance>
>   <BugInstance type="EI_EXPOSE_REP" priority="2">
>     <Class
> classname="dcx.sysman.logging.SMIStatisticsDataBean"/>
>     <Method
> classname="dcx.sysman.logging.SMIStatisticsDataBean"
> name="getCookies"
> signature="()[Ljavax/servlet/http/Cookie;">
>       <SourceLine
> classname="dcx.sysman.logging.SMIStatisticsDataBean"
> start="285" end="285" startBytecode="0"
> endBytecode="4"
> sourcefile="SMIStatisticsDataBean.java"/>
>     </Method>
>     <Field
> classname="dcx.sysman.logging.SMIStatisticsDataBean"
> name="cookies"
> signature="[Ljavax/servlet/http/Cookie;"
> isStatic="false"/>
>     <SourceLine
> classname="dcx.sysman.logging.SMIStatisticsDataBean"
> start="285" end="285" startBytecode="4"
> endBytecode="4"
> sourcefile="SMIStatisticsDataBean.java"/>
>   </BugInstance>
>   <BugInstance type="URF_UNREAD_FIELD" priority="2">
>     <Class
> classname="dcx.sysman.logging.ejb.SMILoggingEJBBean"/>
>     <Field
> classname="dcx.sysman.logging.ejb.SMILoggingEJBBean"
> name="sessionContext"
> signature="Ljavax/ejb/SessionContext;"
> isStatic="false"/>
>   </BugInstance>
>   <BugInstance type="DM_BOOLEAN_CTOR" priority="2">
>     <Class
> classname="dcx.sysman.logging.filter.SMIMessageFilter"/>
>     <Method
> classname="dcx.sysman.logging.filter.SMIMessageFilter"
> name="getSMIScalarProperty"
> signature="(Ljava/lang/String;)Ljava/lang/Object;">
>       <SourceLine
> classname="dcx.sysman.logging.filter.SMIMessageFilter"
> start="113" end="119" startBytecode="0"
> endBytecode="70" sourcefile="SMIMessageFilter.java"/>
>     </Method>
>     <SourceLine
> classname="dcx.sysman.logging.filter.SMIMessageFilter"
> start="116" end="116" startBytecode="31"
> endBytecode="31" sourcefile="SMIMessageFilter.java"/>
>   </BugInstance>
> </BugCollection>
> 
> 
> with regards,
> Deepak.
> 
> 
> 	
> 		
> __________________________________
> Do you Yahoo!?
> Yahoo! Movies - Buy advance tickets for 'Shrek 2'
> http://movies.yahoo.com/showtimes/movie?mid=1808405861 

Current Thread