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
Conferences Close Tree View
+ Stylus Studio Feature Requests (1192)
+ Stylus Studio Technical Forum (14621)
+ Website Feedback (249)
- XSLT Help and Discussion (7625)
-> + Use of before and after string (3) Sticky Topic
-> - How do I substitute element ty... (1)
-> + How does one add working days ... (4)
-> - Help, I have existing XLT and... (1)
-> + Need help on XSLT issue - (2)
-> + EDI to XML Conversion (7)
-> - XML To JSON Conversion using X... (1)
-> + Formatting Paragraphs to same ... (2)
-> - Grouping of records (1)
-> + Problems with xsd 1.1 (4)
-> + XML to HL7 mapping (3)
-> + XSLT 3 and Iterate (2)
-> + XSL-FO to PDF preview (3)
-> + java.lang.RuntimeException: Er... (2)
-> + Create Acroforms with Stylus X... (2)
-> + How to change XSLT parameter s... (3)
-> + how to change format of the da... (2)
-> + Search "Next 8 Results " doesn... (2)
-> - Support for Git (1)
-> + newbee (8)
-- [1-20] [21-40] [41-60] Next
+ XQuery Help and Discussion (2017)
+ Stylus Studio FAQs (159)
+ Stylus Studio Code Samples & Utilities (364)
+ Stylus Studio Announcements (113)
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

   
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.