Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > XML > XSLT
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old October 17th, 2007, 01:47 PM
Authorized User
Points: 251, Level: 5
Points: 251, Level: 5 Points: 251, Level: 5 Points: 251, Level: 5
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: , , Canada.
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.
Reply With Quote
  #2 (permalink)  
Old October 17th, 2007, 02:49 PM
mhkay's Avatar
Wrox Author
Points: 18,487, Level: 59
Points: 18,487, Level: 59 Points: 18,487, Level: 59 Points: 18,487, Level: 59
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
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
Reply With Quote
  #3 (permalink)  
Old October 19th, 2007, 03:54 PM
Authorized User
Points: 251, Level: 5
Points: 251, Level: 5 Points: 251, Level: 5 Points: 251, Level: 5
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: , , Canada.
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
Reply With Quote
  #4 (permalink)  
Old October 20th, 2007, 07:20 AM
joefawcett's Avatar
Wrox Author
Points: 9,763, Level: 42
Points: 9,763, Level: 42 Points: 9,763, Level: 42 Points: 9,763, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Exeter, , United Kingdom.
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)
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 09:48 AM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.