[xsl] Grouping problem (?)

Subject: [xsl] Grouping problem (?)
From: "Dunning, John" <JDunning@xxxxxxxxx>
Date: Mon, 15 Sep 2003 06:12:32 -0400
Hi all,
I suspect this is a grouping problem; I'm trying to increase a number based
on element content, and without any extension functions.

[step 1]
Show the first person's name and address
[step 2]
For each person,
    if the address is the same as the first listed person's
          then display the name in the same table as the first person's
information, adding '1' to the first person's number
[step 3]
For each person
    If the address is different than the first listed person's
        then display the name in a new table with the number incremented by
1.

The problem is in step 3; I can't author a complicated enough match pattern
to return the number I'm looking for; I could compare one element (e.g.,
<street> of each person with the first person, but I want to loop through
all the <address> elements to compare them as well.


Example desired output:

               1   | First Person               |  (Name)
                   |                            | (address)
               ----------------------------------------------
               2   | People with same           |  (names)
                   | address as first person    |
               -----------------------------------------------
[Problem]      3   | Person with different      |  (name)
                   | address                    |  (address)
                ------------------------------------------------
[Problem]      4   | Person with different      |  (name)
                   | address                    |  (address)
                ------------------------------------------------

Sample Data:
<people>
 <person sequence="1">
  <addressbook lang="en">
   <last-name>FIRST</last-name>
   <first-name>Person</first-name>
   <address>
    <street>address</street>
    <city>city</city>
    <state>Virginia</state>
    <postcode>23232</postcode>
    <country>US</country>
   </address>
  </addressbook>
 </person>
 <person sequence="2">
  <addressbook lang="en">
   <last-name>DIFF1</last-name>
   <first-name>Difperson1</first-name>
   <address>
    <street>address2</street>
    <city>city2</city>
    <state>Virginia</state>
    <postcode>21111</postcode>
    <country>US</country>
   </address>
  </addressbook>
 </person>
 <person sequence="3">
  <addressbook lang="en">
   <last-name>SAMEADDRESS1</last-name>
   <first-name>Same1 </first-name>
   <address>
    <street>address</street>
    <city>city</city>
    <state>Virginia</state>
    <postcode>23232</postcode>
    <country>US</country>
   </address>
  </addressbook>
 </person>
 <person sequence="4">
  <addressbook lang="en">
   <last-name>SAMEADDRESS2</last-name>
   <first-name>Second</first-name>
   <address>
    <street>address</street>
    <city>city</city>
    <state>Virginia</state>
    <postcode>23232</postcode>
    <country>US</country>
   </address>
  </addressbook>
 </person>
 <person sequence="5">
  <addressbook lang="en">
   <last-name>DIFF2</last-name>
   <first-name>Persondiff2</first-name>
   <address>
    <street>address3</street>
    <city>city3</city>
    <state>Virginia</state>
    <postcode>21311</postcode>
    <country>US</country>
   </address>
  </addressbook>
 </person>
</people>


I'm using this template to test each person:
<xsl:template name="testSameAddress">
<xsl:variable name="difTest">
	<xsl:for-each select="//person[@sequence !=
'1']/addressbook[1]/address/*">
	<xsl:variable name="nodeName" select="name(.)"></xsl:variable>
		<xsl:choose>
			<xsl:when test="not(text() =
//person[1]/addressbook[1]/address/*[name(.)=$nodeName]/text())">1</xsl:when
>
			<xsl:otherwise>0</xsl:otherwise>
	</xsl:choose>
</xsl:for-each>
</xsl:variable>
<xsl:choose>
	<xsl:when test="contains($difTest,0)">
		<tr><td><b>2</b>-1</td>
			<td>additional people at same address</td>
			<td>
				<xsl:call-template
name="showSamepersonAddress"/>
			</td>
		</tr>
	</xsl:when>
	<xsl:otherwise/>
</xsl:choose>


Any response is greatly appreciated; if anyone would like to see the (7kb)
stylesheet I've been working on let me know and I'll send it along.

TIA,
John


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


Current Thread