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

xsl:sort

Status
Not open for further replies.

EK

Programmer
Mar 15, 2001
3
GB
I have a very simple XML file and used a very simple XSL to form the doc to display in a table form on a HTML page. It displayed okay until I added the xsl:sort to the xsl file, it nows gave me error message "unspecified error" and the page is not displayed at all. The xsl:sort is so simple that I really could not figure out what's wrong with it, can any one help?

Thank you

********************

The XML Document is :

<?xml version=&quot;1.0&quot; ?>
<Customers>
<customer>
<name>Reggie</name>
<address>202 East Haverbrook</address>
<phone>4055551234</phone>
</customer>
<customer>
<name>Jim</name>
<address>3 boolkiel av</address>
<phone>231837</phone>
</customer>
<customer>
<name>Adrian</name>
<address>88 Emmer Green</address>
<phone>168888</phone>
</customer>
<customer>
<name>Kenny</name>
<address>Gee House</address>
<phone>098787</phone>
</customer>
</Customers>


The XSL file is:

<?xml version=&quot;1.0&quot;?>
<xsl:stylesheet xmlns:xsl=&quot;
<xsl:template match=&quot;/&quot;>

<html>
<body>
<h1>events</h1>
<table border=&quot;1&quot; cellpadding=&quot;2&quot;>
<tr>
<td>name</td>
<td>address</td>
<td>phone</td>
</tr>

<xsl:for-each select=&quot;Customers/customer&quot;>
<xsl:sort select=&quot;name&quot;/>
<tr>
<td><xsl:value-of select=&quot;name&quot; /></td>
<td><xsl:value-of select=&quot;address&quot; /></td>
<td><xsl:value-of select=&quot;phone&quot; /></td>
</tr>
</xsl:for-each>
</table>
</body>
</html>

</xsl:template>

</xsl:stylesheet>
 
Can anybody explain to me how to group a xsl:for-each statement?

e.g.
<PERSONS>
<PERSON>
<NAME>John</NAME>
<EXTENSION>232</EXTENSION
</PERSON>
<PERSON>
<NAME>Mary</NAME>
<EXTENSION>122</EXTENSION
</PERSON>
<PERSON>
<NAME>James</NAME>
<EXTENSION>131</EXTENSION
</PERSON>
</PERSONS>

What I need is to transform this to a list using XSLT so that I have an index in this list:

J
James 232
John 131

M
Mary 122

Any suggestions? I hope this helps.

Rob.
 
i'm not entirely sure that this is possible. i say not entirely because i can't believe it can't be done myself.
i'm not sure if you can grab the first letter of an attribute, the nearest thing i can think of is the substring-before() function (altho this definately won't work). it's worth getting a list of all the functions as they get too little coverage in tutorials but are very important in making xslt do anything remotely useful.
but in general grouping in xslt is practically non-existent. the processor &quot;saxon&quot; does have it's own grouping functions which goes away from the w3c standards but then again they don't really provide any useful data processing features.
 
First of all, excuse me for misposting (I didn't want to reply, but start a new thread instead)

Thank you mrTom, although I doesn't really help me. I DID see a tutorial somewhere where the showed you how to 'group' all names (e.g. distinct lastnames), but thats as far as I got. I hope this helps.

Rob.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top