Forum Moderators: open

Message Too Old, No Replies

Sorting with XSL

         

tjhorne

2:30 pm on Mar 31, 2005 (gmt 0)

10+ Year Member



I'm trying to sort my XML file ascending on the "Name" column, I've seen some examples but can't get it too work with my XSL, I have included my XSL file below, please let me know if there is something I can do to get this to work:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<script type="text/javascript" src="find.js"></script>
<head />
<body>
<xsl:for-each select="Database">
<xsl:for-each select="Objects">
<table cellpadding="4" cellspacing="0" width="100%" style="">
<thead>
<tr>
<td class="header"><strong>Name</strong></td>
<td class="header"><strong>Description</strong></td>
<td class="header" width="108"><strong>Email</strong></td>
<td class="header"><strong>Login Name</strong></td>
<td class="header"><strong>Preferred Location</strong></td>
<td class="header"><strong>Active</strong></td>
</tr>
</thead>
<tbody>
<xsl:for-each select="User">
<tr>
<td>
<xsl:for-each select="@name">
<xsl:value-of select="." />
</xsl:for-each>
</td>
<td>
<xsl:for-each select="Description">
<xsl:apply-templates />
</xsl:for-each>
</td>
<td width="108">
<xsl:for-each select="Email">
<a>
<xsl:attribute name="href">mailto:
<xsl:for-each select="@Value">
<xsl:value-of select="." />
</xsl:for-each>
</xsl:attribute>
<xsl:value-of select="@Value"/>
</a>
</xsl:for-each>
</td>
<td>
<xsl:for-each select="LoginName">
<xsl:for-each select="@Value">
<xsl:value-of select="." />
</xsl:for-each>
</xsl:for-each>
</td>
<td>
<xsl:for-each select="UserPreferences">
<xsl:for-each select="PreferredLocation">
<xsl:for-each select="@name">
<xsl:value-of select="." />
</xsl:for-each>
</xsl:for-each>
</xsl:for-each>
</td>
<td>
<xsl:for-each select="Active">
<xsl:for-each select="@Value">
<xsl:value-of select="." />
</xsl:for-each>
</xsl:for-each>
</td>
</tr>
</xsl:for-each>
</tbody>
</table>
</xsl:for-each>
</xsl:for-each>
</body>
</html>
</xsl:template>
</xsl:stylesheet>

irnbru

10:05 pm on Mar 31, 2005 (gmt 0)

10+ Year Member



I'm guessing you're looking for ....

<xsl:for-each select="User">
<xsl:sort select="@name"/>
<tr>
<td>
<xsl:value-of select="@name" />
</td>
</tr>

which will loop over the data and display it ordered by the name attribute.

tjhorne

8:07 pm on Apr 5, 2005 (gmt 0)

10+ Year Member



That worked perfectly, thanks!