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

Problems with variables.

Subject: Problems with variables.
From: "Sargeant, Richard (GEIS)" <Richard.Sargeant@xxxxxxxxxxx>
Date: Fri, 30 Jul 1999 09:55:24 +0200
problems with variables
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

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.