File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes XML and Related Technologies and the fly likes xslt sorting year problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Make it so: Java DB Connections & Transactions this week in the JDBC forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "xslt sorting year problem" Watch "xslt sorting year problem" New topic

xslt sorting year problem

K. Tsang

Joined: Sep 13, 2007
Posts: 3063

Hello all, I try to sort the year field in my xml file using <xsl:sort> by following link but I'm not getting the desired result. Here is my sorting code:

And my xml file consists of tags:
And my schema elements
<xsd:element name="name" type="xsd:string" />
<xsd:element name="description" type="xsd:string" />
<xsd:element name="impl_year" type="xsd:year" />

Then when I load the xml file, 1) I don't see anything and 2) if I have the templates but use <xsl:for-each> tag, then my data isn't sorted. What's going on? Thanks

K. Tsang JavaRanch SCJP5 SCJD OCPJP7 OCPWCD5 OCPBCD5 OCPWSD5 OCMJEA5 part 1 part 2/3
Paul Clapham

Joined: Oct 14, 2005
Posts: 19891

First of all, the <xsl:apply-templates> causes XSLT to process the children of the "system" elements. Those are "name" elements according to your description of the XML. Do you have a template that does that? (I don't see one but maybe you didn't post it.) If not, do you know what XSLT's default processing rule is for an element?

Second, the <xsl:sort> element specifies the sequence for processing those "name" elements. According to your description of the XML, they don't have "impl_year" elements as their children so the sorting won't do anything.
K. Tsang

Joined: Sep 13, 2007
Posts: 3063

Interesting Paul. I will have a look and get back if I have more problems.
I agree. Here's the link:
subject: xslt sorting year problem
It's not a secret anymore!