Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

xsl grouping / looping

Status
Not open for further replies.

ikswoktur

Programmer
Oct 11, 2002
29
US
I am creating a contact list in xml. I want to create a xsl for the list and group the contacts by deptartment. I am guessing there is a way to do this without re-writing the code for every department as the code below indicates.

Thanks!

XML:
<contacts>
<contact>
<name>person1</name>
<dept>dept1</dept>
<title>title</title>
<address1>here</address1>
<address2>and there</address2>
<phone>111.1111</phone>
<email>person1@here</email>
</contact>

<contact>
<name>person3</name>
<dept>dept2</dept>
<title>title</title>
<address1>here</address1>
<address2>and there</address2>
<phone>333.3333</phone>
<email>person3@here</email>
</contact>
</contacts>

XSL TABLE:
<table>
<tr>
<td>
<b>Dept1</b>
</td>
</tr>

<xsl:for-each select=&quot;//contact[dept='dept1']&quot;>
<tr>
<td>
<a>
<xsl:value-of select=&quot;name&quot; />,
<xsl:value-of select=&quot;title&quot; /><br />
<xsl:value-of select=&quot;address1&quot; /><br />
<xsl:value-of select=&quot;address2&quot; /><br />
<xsl:value-of select=&quot;phone&quot; /><br />
<xsl:value-of select=&quot;email&quot; />
</a>
</td>
</tr>
</xsl:for-each>


<tr>
<td>
<b>Dept2</b>
</td>
</tr>


<xsl:for-each select=&quot;//contact[dept='dept2']&quot;>
<tr>
<td>
<a>
<xsl:value-of select=&quot;name&quot; />,
<xsl:value-of select=&quot;title&quot; /><br />
<xsl:value-of select=&quot;address1&quot; /><br />
<xsl:value-of select=&quot;address2&quot; /><br />
<xsl:value-of select=&quot;phone&quot; /><br />
<xsl:value-of select=&quot;email&quot; />
</a>
</td>
</tr>
</xsl:for-each>
</table>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top