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="//contact[dept='dept1']">
<tr>
<td>
<a>
<xsl:value-of select="name" />,
<xsl:value-of select="title" /><br />
<xsl:value-of select="address1" /><br />
<xsl:value-of select="address2" /><br />
<xsl:value-of select="phone" /><br />
<xsl:value-of select="email" />
</a>
</td>
</tr>
</xsl:for-each>
<tr>
<td>
<b>Dept2</b>
</td>
</tr>
<xsl:for-each select="//contact[dept='dept2']">
<tr>
<td>
<a>
<xsl:value-of select="name" />,
<xsl:value-of select="title" /><br />
<xsl:value-of select="address1" /><br />
<xsl:value-of select="address2" /><br />
<xsl:value-of select="phone" /><br />
<xsl:value-of select="email" />
</a>
</td>
</tr>
</xsl:for-each>
</table>
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="//contact[dept='dept1']">
<tr>
<td>
<a>
<xsl:value-of select="name" />,
<xsl:value-of select="title" /><br />
<xsl:value-of select="address1" /><br />
<xsl:value-of select="address2" /><br />
<xsl:value-of select="phone" /><br />
<xsl:value-of select="email" />
</a>
</td>
</tr>
</xsl:for-each>
<tr>
<td>
<b>Dept2</b>
</td>
</tr>
<xsl:for-each select="//contact[dept='dept2']">
<tr>
<td>
<a>
<xsl:value-of select="name" />,
<xsl:value-of select="title" /><br />
<xsl:value-of select="address1" /><br />
<xsl:value-of select="address2" /><br />
<xsl:value-of select="phone" /><br />
<xsl:value-of select="email" />
</a>
</td>
</tr>
</xsl:for-each>
</table>