Subject:Can this mess be sorted? Author:Chris Holmes Date:16 Jan 2007 11:04 AM
I've tried xsl:sort after the for-each, and within apply-templates - but I'm obviously missing something. The code below creates the table exactly as it needs to be, so I'm making progress but I'm stumped on this one.
XML:
<advertisers>
<company>
<companyname>Joe's Bar & Grill</companyname>
<companyurl>www.joesbar.com</companyurl>
</company>
<company>
<companyname>Annabelle's</companyname>
<companyurl>www.annabelles.com</companyurl>
</company>
<company>
<companyname>McCormick & Schmick's</companyname>
<companyurl>www.mccormickandschmicks.com</companyurl>
</company>
<company>
<companyname>Rochester Big & Tall</companyname>
<companyurl>www.rochester.com</companyurl>
</company>
<company>
<companyname>Friendly Center</companyname>
<companyurl>www.friendlycenter.com</companyurl>
</company>
<company>
<companyname>Steak Street</companyname>
<companyurl>www.steakstreet.com</companyurl>
</company>
<company>
<companyname>Boyles</companyname>
<companyurl>www.boyles.com</companyurl>
</company>
<company>
<companyname>Camel City Cafe</companyname>
<companyurl>www.camelcitycafe.com</companyurl>
</company>
</advertisers>
Subject:Can this mess be sorted? Author:James Durning Date:16 Jan 2007 11:48 AM
Assuming you're limited to XSL v1.0:
1. Presort the companies. If you can sort the input beforehand, nothing else needs to change
2. Another solution is to run 2 passes, one to sort, and one for the actual transformation. This however is slow.
3. 2 passes in the same run. Create a temporary variable, which is simply the companies sorted. Then run a for-each on the variable.
Limitations: You need an extension function, probably msxsl:node-set to make this work.