Re: Why I want to change the value of a variable.

Subject: Re: Why I want to change the value of a variable.
From: Francis Norton <francis@xxxxxxxxxxx>
Date: Tue, 26 Oct 1999 12:57:22 +0100
The fact that variables can't vary in XSLT means that it is often easier
to use recursion than for-loops, with the notable exception (I believe)
of situations where you need alphabetic sorting.

In your case you need both changing variables and sorting, so the
solution involves both recursion and a for loop.

It's also worth browsing the XPATH spec for useful functions...

Francis.



<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>

<xsl:output method="html" indent="yes"/>

<xsl:template match="/">
  <HTML>
    <HEAD><TITLE>People list</TITLE></HEAD>
    <BODY>
    <xsl:call-template name="heading">
      <xsl:with-param name="abc" select="'ABCDEFGHIJKLMNOPQRSTUVWXYZ'"
/>
    </xsl:call-template>
    </BODY>
  </HTML>
</xsl:template>

<xsl:template name="heading">
  <xsl:param name="abc" />
  <xsl:variable name="letter" select="substring($abc,1,1)" />
  <CENTER>- <xsl:value-of select="$letter" /> -</CENTER><BR/>
  
  <xsl:for-each select="//PEOPLE[starts-with(NAME, $letter)]">
    <xsl:sort select="NAME"/>
    <xsl:sort select="FIRST_NAME"/>
	
    <xsl:value-of select="concat(FIRST_NAME, ' ', NAME)"/>
    <BR/>
  </xsl:for-each>
  
  <xsl:if test="string-length($abc) != 1">
    <xsl:call-template name="heading">
      <xsl:with-param name="abc" select="substring($abc, 2)" />
    </xsl:call-template>
  </xsl:if>
</xsl:template>

</xsl:stylesheet>


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


Current Thread