Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old December 5th, 2003, 01:48 PM
Registered User
 
Join Date: Dec 2003
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default sorting and document functions

Hello to all.My question is the following:I have a file that contains soem info on cds.Each cd has a position attribute that contains the file in which more information about the cd is stored. How can i sort the elements based on teh values that exist in the various xml files?i want to output xml and not xhtml by the way and i can only have one xsl file to do the transformation...The main xml file looks like this:
<case>
<cd position="cd1.xml">
 ...
<cd position="cd2.xml">
</case>
ANd tehn each file(cd1,2,3...xml) is like this:
<cd>
<artist>blabla</artist>
...
</cd>
I want to sort the cds by artist name.Thanks.

 
Old December 6th, 2003, 12:19 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 147
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to armmarti
Default

Try this (not tested):

Code:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:exsl="http://exslt.org/common">
 <xsl:template match="/">
  <xsl:variable name="all-cds">
   <xsl:for-each select="case/cd">
    <xsl:copy-of select="document(concat('cd', @position, '.xml'))/cd"/>
   </xsl:for-each>
  </xsl:variable>
 
  <sorted-by-artist>
   <xsl:for-each select="exsl:node-set($all-cds)/cd">
    <xsl:sort select="artist"/>
    <xsl:copy-of select="."/>
   </xsl:for-each> 
  </sorted-by-artist> 
 </xsl:template>
</xsl:stylesheet>
Here I think it's impossible to avoid RTF to nodeset conversion. Your XSLT processor must implement EXSLT's node-set() function or something similar.

Regards,
Armen





Similar Threads
Thread Thread Starter Forum Replies Last Post
C functions...??? ethantinder C# 2 April 25th, 2008 02:25 AM
Functions czambran BOOK: Professional JavaScript for Web Developers ISBN: 978-0-7645-7908-0 13 July 11th, 2006 06:33 PM
Datagrid sorting by non alphabetical sorting? LLAndy VS.NET 2002/2003 1 July 15th, 2004 01:20 AM
Help with Functions megabytes C# 1 August 7th, 2003 12:48 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.