Problems with variables.

Subject: Problems with variables.
From: "Sargeant, Richard (GEIS)" <Richard.Sargeant@xxxxxxxxxxx>
Date: Fri, 30 Jul 1999 09:55:24 +0200
I'm trying to suppress a field if the same value appears in the next item. 
For example, if the data looks like this

	<?xml version="1.0"?>
	<PB_LIST>
	 <PB_ITEM>
	  <USER_ID>AAA</USER_ID>
	  <SENDER>7</SENDER>
	  <RECEIVER>24</RECEIVER>
	 </PB_ITEM>
	 <PB_ITEM>
	  <ID>3</ID>
	  <USER_ID>AAA</USER_ID>
	  <SENDER>12</SENDER>
	  <RECEIVER>17</RECEIVER>
	 </PB_ITEM>
	 <PB_ITEM>
	  <USER_ID>BBB</USER_ID>
	  <SENDER>7</SENDER>
	  <RECEIVER>27</RECEIVER>
	 </PB_ITEM>
	</PB_LIST>

I need to create a report with...
   
   User AAA
   	Sender 7    Receiver 24
   	Sender 12   Receiver 17
   User BBB
   	Sender 7    Receiver 27
 	
I therefore tried to make use of a variable but this does not work.

	<xsl:stylesheet xmlns:xsl="http://www.w3.org/XSL/Transform/1.0";>
	<xsl:variable name="varUser">xxx</xsl:variable>
			
	<xsl:template match="*|/">
		<xsl:apply-templates/>
	</xsl:template>
			
	<xsl:template match="PB_ITEM">
		<xsl:apply-templates select="USER_ID"/>
		Sender <xsl:value-of select="SENDER"/>
		Receiver <xsl:value-of select="RECEIVER"/>
		<br/>
	</xsl:template>
	
	<xsl:template match="USER_ID">
		<xsl:choose>
			<xsl:when test="$varUser='.'">
				<xsl:text>-</xsl:text>
			</xsl:when>
			<xsl:otherwise>
				<xsl:variable name='varUser' expr="."/>
				User <xsl:value-of select="."/>
			</xsl:otherwise>
		</xsl:choose>
	</xsl:template>
	
	<xsl:template match="text()"><xsl:value-of
select="."/></xsl:template>
	
	</xsl:stylesheet>

Can anyone see what I'm doing wrong ? Also, is there a better way of
acheiving this ?

regards
   Richard


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


Current Thread