p2p.wrox.com Forums

Need to download code?

View our list of code downloads.


  Return to Index  

xslt thread: Renumbering


Message #1 by "William Carlo Roncallo" <roncalw@y...> on Thu, 19 Jul 2001 19:00:37
You've currently got a loop that's looping round all the records for a
particular country. To get the counting you need, you'll have to add another
level of nesting/grouping, so that all the records for one city are
processed in an inner loop, within which position() will give you the right
answer.

Mike Kay
Software AG

> -----Original Message-----
> From: William Carlo Roncallo [mailto:roncalw@y...]
> Sent: 19 July 2001 19:01
> To: P2P_XSLT
> Subject: [xslt] Renumbering
>
>
> I currently have the following output:
>
> 1France
>   1Paris 1a 2z 3t
>   1Nice 4s 5a 6b
>   1Lyon 7z 8o 9y
> 2Italia
>   2Roma 1x 2p 3r
>   2Milano 4u 5e 6t
>   2Firenze 7b 8n 9a
>   2Napoli 10d 11n 12p
> 3Espana
>   3Madrid 1l 2m 3s
>   3Barcelona 4t 5k 6a
>
> That I want changed to:
> 1France
>   1Paris 1a 2z 3t
>   1Nice 1s 2a 3b
>   1Lyon 1z 2o 3y
> 2Italia
>   2Roma 1x 2p 3r
>   2Milano 1u 2e 3t
>   2Firenze 1b 2n 3a
>   2Napoli 1d 2n 3p
> 3Espana
>   3Madrid 1l 2m 3s
>   3Barcelona 1t 2k 3a
>
> I was hoping for a way to start from 1 again based on a condition or
> something along those lines.
>
> The xml is as follows:
>
> <cities>
>    <city name="Paris" type="a" country="France"/>
>    <city name="Paris" type="z" country="France"/>
>    <city name="Paris" type="t" country="France"/>
>
>    <city name="Roma" type="x" country="Italia"/>
>    <city name="Roma" type="p" country="Italia"/>
>    <city name="Roma" type="r" country="Italia"/>
>
>    <city name="Nice" type="s" country="France"/>
>    <city name="Nice" type="a" country="France"/>
>    <city name="Nice" type="b" country="France"/>
>
>    <city name="Madrid" type="l" country="Espana"/>
>    <city name="Madrid" type="m" country="Espana"/>
>    <city name="Madrid" type="s" country="Espana"/>
>
>    <city name="Milano" type="u" country="Italia"/>
>    <city name="Milano" type="e" country="Italia"/>
>    <city name="Milano" type="t" country="Italia"/>
>
>    <city name="Firenze" type="b" country="Italia"/>
>    <city name="Firenze" type="n" country="Italia"/>
>    <city name="Firenze" type="a" country="Italia"/>
>
>    <city name="Napoli" type="d" country="Italia"/>
>    <city name="Napoli" type="n" country="Italia"/>
>    <city name="Napoli" type="p" country="Italia"/>
>
>    <city name="Lyon" type="z" country="France"/>
>    <city name="Lyon" type="o" country="France"/>
>    <city name="Lyon" type="y" country="France"/>
>
>    <city name="Barcelona" type="t" country="Espana"/>
>    <city name="Barcelona" type="k" country="Espana"/>
>    <city name="Barcelona" type="a" country="Espana"/>
> </cities>
>
> The xsl is as follows:
>
> <xsl:stylesheet
>    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
>    version="1.0">
>
> <xsl:output indent="yes"/>
>
> <xsl:template match="/">
>
>   <xsl:variable name="unique-countries"
>        select="//cities
>                /city[not(@country=preceding-sibling::city/@country)]
>                /@country" />
>
>     <xsl:for-each select="$unique-countries">
>
> 	<xsl:variable name="countrypos">
> 		<xsl:number value="position()" format="1"/>
> 	</xsl:variable>
>
>       <br/>
>
>       <span style="color: blue">
>       	<xsl:value-of select="$countrypos"/>
>       	<xsl:value-of select="."/>
>       </span>
>
>         <xsl:for-each select="//city[@country=current()]">
>
>             <xsl:if test="not(@name=preceding-sibling::city/@name)">
>             	<br/>
>             	<xsl:value-of select="$countrypos"/>
>             	<xsl:value-of select="@name"/>
>             </xsl:if>
>
> 	    <xsl:value-of select="string(' ')"/>
> 	    <xsl:value-of select="position()"/>
>       	    <xsl:value-of select="@type"/>
>
>         </xsl:for-each>
>
>     </xsl:for-each>
>
> </xsl:template>
>
> </xsl:stylesheet>
>
> Can anyone help in any way?
>
> Thanks...
> ---
> When you work at Microsoft, you don't have to wait for the
> latest technologies to be released. You'll create them ? with
> XML, SOAP, and C# -- and help decide what happens next.
> Find out where your career can take you: take a look at our
> software design engineer opportunities at
> http://www.microsoft.com/jobs.
>


  Return to Index