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 October 17th, 2007, 01:47 PM
Authorized User
 
Join Date: Jun 2003
Posts: 60
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to rushman
Default sorting parameters

Hi all!

Let's say I have this XML

<whatever>
  <nbPeople>2</nbPeople>
  <nbAnimals>4</nbAnimals>
  <nbInvertebrates>1</nbInvertebrates>
</whatever>

I already have this in my stylesheet

<xsl:call-template name="print">
  <xsl:with-param name="people" select="nbPeople"/>
  <xsl:with-param name="animals" select="nbAnimals"/>
  <xsl:with-param name="invertebrates" select="nbInvertebrates"/>
</xsl:template>


I'd like to print out a line with params sorted, like:

"1 invertebrate, 2 people, 4 animals"

I want to use <xsl:sort> some way, but I can't figure out how...

<xsl:template name="print">
  <xsl:param name="people"/>
  <xsl:param name="animals"/>
  <xsl:param name="invertebrates"/>

  <xsl:for-each select=" ? ">



  </xsl:for-each>



</xsl:template>


Any help will be appreciated,

Rushman
__________________
Dijkstra's law on Programming and Inertia:

If you don't know what your program is supposed to do, don't try to write it.
 
Old October 17th, 2007, 02:49 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

You can do

<xsl:for-each select="$people|$animals|$invertebrates">
  <xsl:sort select="." data-type="number"/>


Alternatively, why not pass a single parameter which can be either (a) the union of these three node-sets, or (b) the parent <whatever> element?

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old October 19th, 2007, 03:54 PM
Authorized User
 
Join Date: Jun 2003
Posts: 60
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to rushman
Default

Thanks Mister Kay for your answer. However, after reviewing my XML and XSL, I realized that it was a little more complicated. In fact, the parameters get passed as a sum instead of passing the elements. i.e.:

<whatever>
  <nbPeople>2</nbPeople>
  <nbAnimals>4</nbAnimals>
  <nbPeople>1</nbPeople>
  <nbInvertebrates>1</nbInvertebrates>
</whatever>

I already have this in my stylesheet

<xsl:call-template name="print">
  <xsl:with-param name="people" select="sum(nbPeople)"/>
  <xsl:with-param name="animals" select="sum(nbAnimals)"/>
  <xsl:with-param name="invertebrates" select="sum(nbInvertebrates)"/>
</xsl:template>

I'd like to print out a line with params sorted, like:

"1 invertebrate, 3 people, 4 animals"

I can't use <xsl:for-each select="$people|$animals|$invertebrates"> since these variable are numbers now...

I'm using XSLT 1.0 with Xalan (Eh! It's not MY choice...) Maybe an extension function can help me somehow...

Thanks again,

Rushman
 
Old October 20th, 2007, 07:20 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

It can't be done unless you either pass the names along with the totals or have some sort of look up within the template. Information loss occur when you sum before passing to the template. You're better off redesigning as Michael suggests and passing the parent node to begin with.

--

Joe (Microsoft MVP - XML)





Similar Threads
Thread Thread Starter Forum Replies Last Post
sorting member XSLT 25 July 13th, 2007 08:44 AM
Sending over a sorting parameters segeller Crystal Reports 4 September 4th, 2005 07:58 PM
sorting kondapally Crystal Reports 2 January 21st, 2005 10:51 AM
Datagrid sorting by non alphabetical sorting? LLAndy VS.NET 2002/2003 1 July 15th, 2004 01:20 AM
Need help Sorting athanatos XSLT 5 August 11th, 2003 07:51 PM





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