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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

newbie ? - Grouping with XSLT

Status
Not open for further replies.

NatGreen

Programmer
Apr 19, 2002
90
US
I would like to be able to group my data, but I am not sure on the best way to go about this. Here is the structure before and what I would like to see afterwards.

Before:
<NewRoot>
<General>
<field1>x</field1>
<field2>y</field2>
<field3>z</field3>
<General>
<NewRoot>

After:
<NewRoot>
<General>
<!---For Each Distinct Field1-->
<field1>
<field2>y</field2>
<field3>z</field3>
</field1>
</General>
</NewRoot>

Can anyone point me in the right direction or does anyone know of some good articles to read?

Thanks in advance,
Nat
 
I ended up doing something completely different with my XSLT.

Here is what I ended up doing:
<?xml version='1.0'?>
<xsl:stylesheet xmlns:xsl=&quot; version=&quot;1.0&quot;>
<xsl:eek:utput method=&quot;html&quot; />

<xsl:variable name=&quot;Table&quot; select=&quot;//Table&quot; />

<!-- Template for root rule -->
<xsl:template match=&quot;/&quot;>
<xsl:apply-templates />
</xsl:template>

<xsl:template match=&quot;NewDataSet&quot;>


<xsl:for-each select=&quot;$Table&quot;>

<!-- Sort Primary key ascending order -->
<xsl:sort select=&quot;Field1&quot; order=&quot;ascending&quot; />

<xsl:variable name=&quot;Field1&quot; select=&quot;Field1&quot; />
<xsl:if test=&quot;generate-id(.)=generate-id($Table[Field1=$Field1])&quot;>

<!-- Display the table header -->
<h5>
<xsl:value-of select=&quot;Field1&quot; />
</h5>

<!-- Display all node headers-->
<table class=&quot;bordertext&quot; cellSpacing=&quot;0&quot; cellPadding=&quot;1&quot; border=&quot;0&quot; >
<tr>
<th width=&quot;50&quot;>Detail Link</th>
<th width=&quot;75&quot;>Field 2</th>
<th width=&quot;100&quot;>Field 3</th>
<th width=&quot;75&quot;>Field 4</th>
<th width=&quot;150&quot;>Field 5</th>
<th width=&quot;50&quot;>Field 6</th>
<th width=&quot;175&quot;>Field 7</th>
</tr>

<xsl:for-each select=&quot;$Table[Field1=$Field1]&quot;>

<xsl:sort select=&quot;Field 3&quot; order=&quot;ascending&quot;/>
<xsl:sort select=&quot;Field 4&quot; order=&quot;ascending&quot;/>
<tr>
<td>
<a>
<xsl:attribute name=&quot;href&quot;>
<xsl:text>#</xsl:text>
</xsl:attribute>
<xsl:attribute name=&quot;onclick&quot;>
<xsl:text>window.open('../New/Details.aspx?Id=</xsl:text>
<xsl:value-of select=&quot;Field9&quot; />
<xsl:text>', 'new', 'toolbars=no scrollbars=yes')</xsl:text>
</xsl:attribute>
View
</a>
</td>
<td align=&quot;center&quot;>
<xsl:value-of select=&quot;Field 2&quot; />
</td>
<td>
<xsl:value-of select=&quot;Field 3&quot; />
</td>
<td>
<xsl:choose>
<xsl:when test=&quot;Field 4!=''&quot;>
<xsl:variable name=&quot;Date&quot; select=&quot;Field 4&quot; />
<Field 4>
<!-- Month -->
<xsl:value-of select=&quot;substring($Date,6,2)&quot;/>
<xsl:text>/</xsl:text>
<!-- Day -->
<xsl:value-of select=&quot;substring($Date,9,2)&quot;/>
<xsl:text>/</xsl:text>
<!-- Year -->
<xsl:value-of select=&quot;substring($Date,1,4)&quot;/>
</Field 4>
</xsl:when>
<xsl:eek:therwise>
<Field 4/>
</xsl:eek:therwise>
</xsl:choose>
</td>
<td>
<xsl:value-of select=&quot;Field 5&quot; />
</td>
<td align=&quot;center&quot;>
<xsl:value-of select=&quot;Field 6&quot; />
</td>
<td>
<xsl:value-of select=&quot;Field 7&quot; />
</td>
</tr>
</xsl:for-each>
</table>
<br />
<br />
</xsl:if>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>

Regards,
NatGreen
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top