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 February 17th, 2016, 06:45 PM
Registered User
 
Join Date: Dec 2015
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default XSLT Custom Sort Order

I want custom order of title, but I am not able to get it, I tried this but it did not work

<xsl:template match="/">
<table class="stripeMe" width="700" cellpadding="5" cellspacing="1">
<thead>
<tr>
<td>Employee Name</td>
<td>Position</td>
<td>CALL US Extension</td>
<td>Direct Line</td>
</tr>

</thead>

<xsl:for-each select="Users/User_Detail">
<xsl:sort select="string-length(substring-before('|District Director|Assitant District Director|ADD|', concat('|', title, '|')))" data-type="number"/>
<xsl:sort select="last_name" order="ascending" />
 
Old February 18th, 2016, 07:40 AM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

Based on my none-existent knowledge of what your input XML looks like this will work.
__________________
/- Sam Judson : Wrox Technical Editor -/

Think before you post: What have you tried?
 
Old February 18th, 2016, 08:13 AM
Registered User
 
Join Date: Dec 2015
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default my xml is

<Users>
<User_Detail>
<last_name>Gauza</last_name>
<first_name>Thomas</first_name>
<office_id>149</office_id>
<new_extension>11235</new_extension>
<current_phone_number>123-456-7890</current_phone_number>
<title>District Director</title>
<Region>5</Region>
</User_Detail>
<User_Detail>
<last_name>Pratt</last_name>
<first_name>Richard</first_name>
<office_id>149</office_id>
<new_extension>852963</new_extension>
<current_phone_number>123-456-0789</current_phone_number>
<title>Assistant District Director</title>
<Region>5</Region>
<User_Detail>
<last_name>Green</last_name>
<first_name>Latonya</first_name>
<office_id>5</office_id>
<new_extension>400029</new_extension>
<current_phone_number>312-596-7200</current_phone_number>
<title>Compliance Specialist</title>
<Region>5</Region>
</User_Detail>
</User_Detail>

</Users>
 
Old February 18th, 2016, 10:00 AM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

Assuming Users is the root element of your XSLT then this works fine for me.

You are aware that Latonya Green's User_Detail is actually embedded inside the User_Detail for Richard Pratt, so is never output, right, and you've spelt Assistant wrong in the sort statement?

Also, "|District Director|" returns an empty string - so does a none-match. Try putting an "X" at the start of the string to move the correct match up one.
__________________
/- Sam Judson : Wrox Technical Editor -/

Think before you post: What have you tried?

Last edited by samjudson; February 18th, 2016 at 10:06 AM..





Similar Threads
Thread Thread Starter Forum Replies Last Post
Sort words based on custom order JohnBampton XSLT 2 March 2nd, 2014 09:12 AM
xslt 1.0 count, devide and sort (order?) vestlink XSLT 8 October 20th, 2011 09:56 AM
Dynamic sort order or sort datatype kapy_kal XSLT 2 September 18th, 2007 02:10 PM
sort recordset in different order pablohoney Classic ASP Databases 0 December 29th, 2005 08:32 PM
Sort order Question Tere Crystal Reports 1 February 14th, 2005 03:18 PM





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