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

Why I want to change the value of a variable.

Subject: Why I want to change the value of a variable.
From: "Emmanuel.Leguy" <Emmanuel.Leguy@xxxxxxx>
Date: Tue, 26 Oct 1999 11:21:50 +0200
emmanuel leguy
David Carlisle wrote:
> 
> > Is it possible in xsl to change the value of a variable?
> 
> No.

So why is it called 'variable'?
 
> If you said what you _really_ wanted to do (ie what effect you wanted to
> achieve) then no doubt someone could help.

OK.

I have a list of people in a XML format:

<LIST_PEOPLE>
	<PEOPLE>
	      <FIRST_NAME>Emmanuel</FIRST_NAME>
	      <NAME>Leguy</NAME>
	</PEOPLE>
	<PEOPLE>
	      <FIRST_NAME>Sam</FIRST_NAME>
	      <NAME>Kememer</NAME>
	</PEOPLE>
	<PEOPLE>
	      <FIRST_NAME>Gilles</FIRST_NAME>
	      <NAME>Presley</NAME>
	</PEOPLE>
	<PEOPLE>
	      <FIRST_NAME>Marie-Pierre</FIRST_NAME>
	      <NAME>Smith</NAME>
	</PEOPLE>
	<PEOPLE>
	      <FIRST_NAME>Eve</FIRST_NAME>
	      <NAME>Ramone</NAME>
	</PEOPLE>
	<PEOPLE>
	      <FIRST_NAME>Florence</FIRST_NAME>
	      <NAME>Lerouge</NAME>
	</PEOPLE>
	<PEOPLE>
	      <FIRST_NAME>Marc</FIRST_NAME>
	      <NAME>Duchmol</NAME>
	</PEOPLE>
	<PEOPLE>
	      <FIRST_NAME>Yves</FIRST_NAME>
	      <NAME>Durant</NAME>
	</PEOPLE>
	<PEOPLE>
	      <FIRST_NAME>Maria</FIRST_NAME>
	      <NAME>Dupuis</NAME>
	</PEOPLE>
	<PEOPLE>
	      <FIRST_NAME>Laurent</FIRST_NAME>
	      <NAME>Leclercq</NAME>
	</PEOPLE>
	<PEOPLE>
	      <FIRST_NAME>Chris</FIRST_NAME>
	      <NAME>Dupont</NAME>
	</PEOPLE>
	<PEOPLE>
	      <FIRST_NAME>Alan</FIRST_NAME>
	      <NAME>Stivell</NAME>
	</PEOPLE>
	<PEOPLE>
	      <FIRST_NAME>Gweltaz</FIRST_NAME>
	      <NAME>Ar Fur</NAME>
	</PEOPLE>
</LIST_PEOPLE>

and I would like to transform it in html:

<HTML>
<HEAD><TITLE>People list</TITLE></HEAD>
<BODY>
<CENTER>- A -</CENTER><BR>
Gweltaz Ar Fur<BR>
<CENTER>- B -</CENTER><BR>nobody<BR>
<CENTER>- C -</CENTER><BR>nobody<BR>
<CENTER>- D -</CENTER><BR>
Marc Duchmol<BR>
Chris Dupont<BR>
Maria Dupuis<BR>
Yves Durant<BR>
<CENTER>- E -</CENTER><BR>nobody<BR>
<CENTER>- F -</CENTER><BR>nobody<BR>
<CENTER>- G -</CENTER><BR>nobody<BR>
<CENTER>- H -</CENTER><BR>nobody<BR>
<CENTER>- I -</CENTER><BR>nobody<BR>
<CENTER>- J -</CENTER><BR>nobody<BR>
<CENTER>- K -</CENTER><BR>
Sam Kememer<BR>
<CENTER>- L -</CENTER><BR>
Laurent Leclercq<BR>
Emmanuel Leguy<BR>
Florence Lerouge<BR>
<CENTER>- M -</CENTER><BR>nobody<BR>
<CENTER>- N -</CENTER><BR>nobody<BR>
<CENTER>- O -</CENTER><BR>nobody<BR>
<CENTER>- P -</CENTER><BR>
Gilles Presley<BR>
<CENTER>- Q -</CENTER><BR>nobody<BR>
<CENTER>- R -</CENTER><BR>
Eve Ramone<BR>
<CENTER>- S -</CENTER><BR>
Marie-Pierre Smith<BR>
Alan Stivell<BR>
<CENTER>- T -</CENTER><BR>nobody<BR>
<CENTER>- U -</CENTER><BR>nobody<BR>
<CENTER>- V -</CENTER><BR>nobody<BR>
<CENTER>- W -</CENTER><BR>nobody<BR>
<CENTER>- X -</CENTER><BR>nobody<BR>
<CENTER>- Y -</CENTER><BR>nobody<BR>
<CENTER>- Z -</CENTER><BR>nobody<BR>
</BODY>
</HTML>

To do this i use this algorithm:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/TR/WD-xsl"
indent-result="yes">

<xsl:template match="/">
  <HTML>
    <HEAD><TITLE>People list</TITLE></HEAD>
    <BODY>
      <!-- declaration of curentChar -->
      <xsl:for-each select="LIST_PEOPLE/PEOPLE">
        <xsl:sort select="NAME"/>
        <xsl:sort select="FIRST_NAME"/>
	<xsl:variable name="firsChar">
	    <xsl:value-of select="substring(NAME,1,1)"/>
	</xsl:variable>
	<xsl:if test="not(string(curentChar)=string(firstChar))">
	     <CENTER>- <xsl:value-of select="$firstChar"/> -</CENTER><BR/>
	     <!-- put the firstChar value into curentChar -->
	</xsl:if>
	<xsl:value-of select="FIRST_NAME"/>
	<xsl:text>&nbsp;</xsl:text>
	<xsl:value-of select="NAME"/>
	<BR/>
      </xsl:for-each>
    </BODY>
  </HTML>
</xsl:template>

</xsl:stylesheet> 

Manu.
--
Laboratoire d'Informatique Fondamentale de Lille (LIFL)
Universite des Sciences et Technologies de Lille
Batiment M3 Cite Scientifique
59655 Villeneuve d'Ascq Cedex
FRANCE
tel: 03 20 33 63 38
fax: 03 20 43 65 66
mailto:Emmanuel.Leguy@xxxxxxx
http://www.lifl.fr


 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.