[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

RE: [xsl] recursive function?


Subject: RE: [xsl] recursive function?
From: <Jarno.Elovirta@xxxxxxxxx>
Date: Mon, 24 Jan 2005 10:16:39 +0200

Hi,

> A simple version of my Xml looks like this;
>
> <Result>
>
> <Person>
>   <Name>Pete</Name>
>   <City>New York</City>
> </Person>
>
> <Person>
>   <Name>Tom</Name>
>   <City>Chicago</City>
> </Person>
>
> <Person>
>   <Name>Lisa</Name>
> </Person>
>
> <Person>
>   <Name>Bart</Name>
> </Person>
>
> </Result>
>
>
> I would like mye page to look something like this:
>
> Pete - New York
> Tom - Chicago
>
> People not connected to city:
> Lisa
> Bart
>
>
> In my for-each Person loop I know i can check if City exists
> and if not
> write the line "People not  connected to city:". But how can
> I do this only
> once - before the first person not having a City node? (The
> ones without
> City will always come last in the listing). I guess I will
> have to use a
> recursive funcion, but how will this work when I'm using the for-each
> looping through the records?

Instead of testing for city inside the for-each, why not only select the
Person elements you want? I.e. first

<xsl:for-each select="Person[City]">
  <xsl:value-of select="concat(Name, ' - ', City)"/>
</>

And then

<xsl:text>People not connected to city:</xsl:text>
<xsl:for-each select="Person[not(City)]">
  <xsl:value-of select="concat(Name, ' - ', City)"/>
</>

Cheers,

Jarno


Current Thread
Keywords
xml