XML Editor
Sign up for a WebBoard account Sign Up Keyword Search Search More Options... Options
Chat Rooms Chat Help Help News News Log in to WebBoard Log in Not Logged in
Show tree view Topic
Topic Page 1 2 3 4 5 6 7 8 9 Go to previous topicPrev TopicGo to next topicNext Topic
Postnext
Chris HolmesSubject: 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 &amp; Grill</companyname>
<companyurl>www.joesbar.com</companyurl>
</company>
<company>
<companyname>Annabelle's</companyname>
<companyurl>www.annabelles.com</companyurl>
</company>
<company>
<companyname>McCormick &amp; Schmick's</companyname>
<companyurl>www.mccormickandschmicks.com</companyurl>
</company>
<company>
<companyname>Rochester Big &amp; 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>

XSL:

<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:param name="pagesize" select="3"/>

<xsl:template match="advertisers">
<body>
<table border="0" width="100%" cellspacing="0">
<xsl:for-each select="company[position() mod $pagesize = 1]">
<tr>
<xsl:for-each select=". | following-sibling::company[position() &lt; $pagesize]">
<td width="33%" class="normaltext">
<a>
<xsl:attribute name="href">http://
<xsl:value-of select="companyurl"/>
</xsl:attribute>
<xsl:copy-of select="companyname"/>
</a>
</td>
</xsl:for-each>
</tr>
</xsl:for-each>
</table>
</body>
</xsl:template>
</xsl:stylesheet>

Thanks in advance.
-Chris

Postnext
James DurningSubject: 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.

Posttop
Chris HolmesSubject: Can this mess be sorted?
Author: Chris Holmes
Date: 16 Jan 2007 12:38 PM
I assumed presorting would be the way to go. Problem is that it seems easier said than done. I can't seem to get the tags in the correct position.

-Chris

 
Topic Page 1 2 3 4 5 6 7 8 9 Go to previous topicPrev TopicGo to next topicNext Topic
Download A Free Trial of Stylus Studio 6 XML Professional Edition Today! Powered by Stylus Studio, the world's leading XML IDE for XML, XSLT, XQuery, XML Schema, DTD, XPath, WSDL, XHTML, SQL/XML, and XML Mapping!  
go

Log In Options

Site Map | Privacy Policy | Terms of Use | Trademarks
Stylus Scoop XML Newsletter:
W3C Member
Stylus Studio® and DataDirect XQuery ™are from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2016 All Rights Reserved.