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 August 10th, 2007, 05:11 PM
Registered User
 
Join Date: Aug 2007
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Stumped on XSLT template


Thanks for your help Bill.
 
Old August 10th, 2007, 05:37 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

First, make sure you're using an XSLT 2.0 processor (Saxon or Altova).

Then it's just

<xsl:variable name="sorted_status" as="element()">
  <xsl:perform-sort select="STATUS">
    <xsl:sort select="xs:date(@_Date)"/>
  </xsl:perform-sort>
</xsl:variable>

then you can access $sorted_status[last()]




Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old August 10th, 2007, 05:38 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

Sorry, typo there, should be as="element()*".

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old August 11th, 2007, 10:02 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

You need to understand the concept of "context". The select expression for xsl:sort is evaluated once for each node being sorted, with that node as the context node. If the expression starts with "//" then it's going to return the same value each time, regardless what node you're starting at.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old August 14th, 2007, 10:33 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

As I said before, the path expression used in xsl:sort needs to select starting at the context node. An absolute path expression starting with "/" is almost invariably wrong.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old August 14th, 2007, 07:05 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

If you read the specs (or any book or tutorial) you will see that path expressions beginning with "/" or "//" both select relative to the root of the document, so they suffer from the same problem.

If you don't read any spec or book or tutorial, then you will remain forever stumped - you won't even understand the answers when you ask a technical question.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old October 16th, 2007, 03:44 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

Since you've deleted the comments that I was replying to, and since it was months ago, I can't recall what was said that caused me to become so irritated. But judging from the time I devoted to explaining the simplest of concepts found in the first few pages of any textbook, I strongly suspect that I was being extremely patient.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old December 19th, 2007, 01:55 PM
Registered User
 
Join Date: Dec 2007
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Michael Kay,

  I saw the original messages. Working in Biztalk, the fellow's questions were quite justified as your responses didn't apply. You should consider being kinder to people new in XSLT. Just because they are struggling with an issue doesn't mean they haven't done their homework and read a book.

Sam

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

Sam,

Sorry, but as the record of one half of the conversation has been deleted, presumably by the originator, I cannot comment on whether my responses were reasonable or not.

I actually think it's pretty discourteous to delete your questions from the forum once they have been answered. It means the information I've taken trouble to provide is no use to anyone else, which in effect means I was wasting my time in providing it.

I freely admit I have off days; when you've answered the same question dozens of times, it's easy to forget that you're not teaching the same class of students, but that each questioner is arriving independently with the same baseline of zero knowledge. I don't often get irritated unless people are blatantly ignoring my responses. But I do often answer tersely, on the theory that any answer is better than none, and some people take that the wrong way.

If you like, I'll stop answering them.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference





Similar Threads
Thread Thread Starter Forum Replies Last Post
XSLT: ONE template to transform all the elements Behl_Neha XSLT 8 December 15th, 2007 07:31 PM
XSLT Template Issue saravanan.k XSLT 2 March 14th, 2007 06:41 AM
Stumped, need XSLT Help foobar XSLT 3 July 3rd, 2006 11:07 AM
XSLT Template error again bmains XSLT 4 December 19th, 2003 11:17 AM
XSLT - First Time Matching a Template highlife XSLT 4 July 25th, 2003 07:50 AM





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