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 31st, 2007, 01:34 PM
Authorized User
 
Join Date: Jun 2003
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to victorcorey
Default Sorting number, but omit null

I have an xml file that some of the nodes do not contain a child that I use to sort.
<priceModule>
  <row>
    <name>Item 1</name>
    <priceCol>600</priceCol>
  </row>
  <row>
    <name>Item 2</name>
  </row>
</priceModule>

I need to sort by priceCol, but omit the rows that do not contain a priceCol from the sort.

Thanks,Victor

--
Victor Corey
__________________
--
Victor Corey
 
Old December 31st, 2007, 02:03 PM
Friend of Wrox
 
Join Date: Nov 2007
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 Posts
Default

Do you use XSLT 1.0 or 2.0?
And what exactly should happen with elements that do not have a priceCol, do you not want to process them at all or do you want to process them after the elements which have a priceCol?

 
Old December 31st, 2007, 02:15 PM
Authorized User
 
Join Date: Jun 2003
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to victorcorey
Default

I am using xslt 2.0.

Right now if I sort by priceCol:
<xsl:sort order="ascending" select="priceCol" data-type="number" />

It sorts correctly except it puts the items without that node at the top. I need these at the bottom.

Thanks,
Victor

--
Victor Corey
 
Old December 31st, 2007, 02:20 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

Add a second sort key:

<xsl:sort order="ascending" select="empty(priceCol)">
<xsl:sort order="ascending" select="number(priceCol)"/>

false sorts before true, so nodes with no priceCol will sort at the end.


Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old December 31st, 2007, 02:24 PM
Authorized User
 
Join Date: Jun 2003
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to victorcorey
Default

I get this error:

'empty' is not a valid XSLT or XPath function. -->empty(priceCol)<--

--
Victor Corey
 
Old December 31st, 2007, 02:33 PM
Friend of Wrox
 
Join Date: Nov 2007
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 Posts
Default

empty is defined in XPath 2.0, see http://www.w3.org/TR/xpath-functions/#func-empty
Therefore I am not sure why you get that error as you stated you use XSLT 2.0 (where all XPath 2.0 functions are available).



 
Old December 31st, 2007, 02:33 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

You said you were using XSLT 2.0, it seems that you were mistaken. XSLT 1.0 doesn't allow sorting of booleans, but you can achieve the same effect using select="not(priceCol)" which generates the sort keys "false" and "true" as strings.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old December 31st, 2007, 02:39 PM
Authorized User
 
Join Date: Jun 2003
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to victorcorey
Default

I have this at the top of my xslt <xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema">, But I'm very new to it.

Would empty evaluate if the node does not even exist, not just empty.

Thanks,
Victor

--
Victor Corey
 
Old December 31st, 2007, 02:41 PM
Authorized User
 
Join Date: Jun 2003
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to victorcorey
Default

Well, I must be using 1.0, becuase not(priceCol) worked. Thank you.

I just started using xslt and continue to learn how powerful it is. Thanks for you help.

Why am I using 1.0 when I put 2.0 in the stylesheet directions?

Thanks,
Victor

--
Victor Corey
 
Old December 31st, 2007, 02:45 PM
Friend of Wrox
 
Join Date: Nov 2007
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 Posts
Default

Whether XSLT 2.0 is supported depends on the XSLT processor you use, not on the version attribute.
Current XSLT 2.0 processors are Saxon, Gestalt, and Altova.
If you use an XSLT 1.0 processor to run an XSLT stylesheet with version="2.0" then the processor tries to run it in forwards compatible mode http://www.w3.org/TR/xslt#forwards.





Similar Threads
Thread Thread Starter Forum Replies Last Post
I need to omit the duplicate values when displayin ppakala XSLT 1 June 24th, 2008 06:13 PM
Omit xmlns Pankaj C XSLT 3 July 31st, 2007 10:18 AM
omit-xml-declaration dextermagnific XSLT 3 August 4th, 2006 09:55 AM
How to set Not Null constraint to Null Columns arasu Oracle 1 August 22nd, 2005 10:09 AM
Omit negative values in Queries - Access 97 snoopy92211 Access VBA 1 October 13th, 2004 12:24 PM





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