BizTalk Utilities CV ,   Jobs ,   Code library
 
Home Page


Add/Edit your code items
Search the code library
Browse for the code library


Uncategorized
Positional grouping by number of items
Parsing XML tag elements with VB string functions
getTemplate
getProcessor
Padding with spaces to a fixed-length string
Re: Swapping values in two integer variables without using a temporary variable
Swapping values in two integer variables without using a temporary variable
Comparing Multiple fields from the subquery
Re: Filtering unique values
Re: Grouping with totals/subtotals -- nested Muenchian method
Grouping with totals/subtotals -- nested Muenchian method
Generic JScript Function To Load XML Data
WebCube Report - Browser-based Multidimensional Data Reporting
The pow(a, b) function
Re: Missing constant definition
A simple template to display singular and plural counts
swapping two integer values without using temporary
Debugging script
Combinations of k out of n numbers
Permutations of the values of N nodes


 
 

<< System.XMLWCF, WS, SOAP >>


By Mark Wilson
I am the creator of TopXML. I am available for international and local (Australia) contracts. I am a Solution Architect/Business Analyst. I have worked in IT in several countries (NZ, Australia, South Africa, UK) building and training teams for government and very large non-governmental organizations. I am ex-Microsoft Consulting Services. I wrote the first book on Microsoft XML published in 2000 called XML Programming with VB and ASP. Most recently I have been building tools for the SEO industry. Ask me for a 37 point SEO health-checkup for your website.
First Posted 02/27/2001
Times viewed 279

Sorting on Dates and other Fixed Formats using the substring Function


Summary The Substring function can be very powerful when sorting especially with time and date formats.

Substring Function format
substring(value, start, length)

Characters within a string are numbered 1, 2, 3 ... n.
Michael Kay XSLT Programmers Reference
Let's look at a few examples:
First lets look at a date in the format
mm/dd/yyyy
mm/dd/yyyy
<xsl:sort order=ascending select=substring(text(), 7,4) />
<xsl:sort order=ascending select=substring(text(), 1,2) />
<xsl:sort order=ascending select=substring(text(), 4,2) />
The first sort element singles out the
yyyy 
and sorts on that first.
The second sort element singles out the
mm 
and sorts on that.
The third sort element singles out the
dd 
and sorts on that
Different date formats are just as simple. Different formats just require adjusting the substring functios
yyyy/mm/dd
<xsl:sort order=ascending select=substring(text(), 1,4) />
<xsl:sort order=ascending select=substring(text(), 6,2) />
<xsl:sort order=ascending select=substring(text(), 9,2) />
dd/mm/yyyy
<xsl:sort order=ascending select=substring(text(), 7,4) />
<xsl:sort order=ascending select=substring(text(), 4,2) />
<xsl:sort order=ascending select=substring(text(), 1,2) />
hh:mm:ss
<xsl:sort order=ascending select=substring(text(), 1,2) />
<xsl:sort order=ascending select=substring(text(), 4,2) />
<xsl:sort order=ascending select=substring(text(), 7,2) />
One interesting sidenote if you want to do something with the sorted nodes after they are sorted
i.e. position() use the apply-templates rather than for-each

Additional information

Further additional information


Rate this article on a scale of 1 to 10 (0 votes, average 0)

Your vote :  

<< System.XMLWCF, WS, SOAP >>





Leave a comment for this article
Your name
Your email (optional)
Your comment
Optional: Upload an attachment
Enter the code shown:

 
 

    Email TopXML