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 February 14th, 2006, 09:27 AM
Registered User
Join Date: Feb 2006
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default Sorting with XSL

Hello, I hope someone can help me.
I have the folloging XML data:

  <article id="1" order="50" show="yes">
    <value>value of group1</value>


  <article id...

I am using a <xsl:for-each > instruction to loop through all articles. When I want to sort the articles by the price it works fine with <xsl:sort select="*[name()='article_price']" /> after the <xsl:for-each>.

But I don´t know what to do to sort the articles for example by the <value> of <article_group>´s with the <name>Quality</name>.

Any one have an idea?
Thanks you very much in advance.

Greetings, Wolfgang
Old February 14th, 2006, 10:19 AM
joefawcett's Avatar
Wrox Author
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts

For your first sort you can simplify to:
<xsl:sort data-type="number" select="article_price" />
For the sort based on article_group/name equal to "quality":
<xsl:sort data-type="text" select="article_groups/article_group[name = 'Quality']/value" />
This assumes that the value element has text data, if it's a number then change data-type attribute to "number".


Joe (Microsoft MVP - XML)
Old February 14th, 2006, 10:25 AM
mhkay's Avatar
Wrox Author
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts

>it works fine with <xsl:sort select="*[name()='article_price']" />

It would work even finer with <xsl:sort select="article_price"/>

>But I don´t know what to do to sort the articles for example by the <value> of <article_group>´s with the <name>Quality</name>.

<xsl:sort select="article_groups/article_group[name='Quality']/value"/>

Michael Kay
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference

Similar Threads
Thread Thread Starter Forum Replies Last Post
sorting decimal values in xsl SOMANATHAN10 XSLT 1 May 10th, 2007 07:47 AM
xsl sorting ramuis78 XSLT 0 June 9th, 2006 01:51 PM
Sorting a xsl:if test="position()" charmaigne XSLT 2 April 12th, 2006 04:42 AM
Sorting element in xsl Sakubar Sathik XSLT 5 April 6th, 2006 04:23 AM
XSL Sorting using variable mannabaron XSLT 4 February 15th, 2006 06:13 AM

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