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 September 23rd, 2008, 04:30 AM
Friend of Wrox
 
Join Date: Jun 2008
Posts: 291
Thanks: 9
Thanked 29 Times in 29 Posts
Default Function for Sort

Is there any function to Sort some text? I came through Xpath sort() function. But if I use it in Oxygen Editor, an error arise saying "unknown system function sort()". Actually I solved my problem, but I need to be clear of these functions.
Please provide some ideas.

__________________
Rummy
 
Old September 23rd, 2008, 04:42 AM
Friend of Wrox
 
Join Date: Nov 2007
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 Posts
Default

With XSLT 1.0 and 2.0 you can process nodes (or in XSLT 2.0 items) in sorted order using the xsl:sort element, see http://www.w3.org/TR/xslt#sorting, where you put one or more xsl:sort elements as children of xsl:for-each or xsl:apply-templates (or xsl:for-each-group in XSLT 2.0).
In XSLT 2.0 there is additionally xsl:perform-sort http://www.w3.org/TR/xslt20/#creating-sorted-sequence

I don't think there is a sort function in pure XPath.

--
  Martin Honnen
  Microsoft MVP - XML
 
Old September 23rd, 2008, 04:54 AM
Friend of Wrox
 
Join Date: Jun 2008
Posts: 291
Thanks: 9
Thanked 29 Times in 29 Posts
Default

Thanks Martin. I'm interested in functions related to sort in xslt 2.0. Is there any method to do that through any of the functions present?

 
Old September 23rd, 2008, 05:01 AM
Friend of Wrox
 
Join Date: Nov 2007
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 Posts
Default

I have pointed you to the xsl:sort and xsl:perform-sort documentation. What else do you need?
If you need more help then show us the input you want to sort and the sorted result you want to achieve, then we can provide an example using xsl:sort.

--
  Martin Honnen
  Microsoft MVP - XML
 
Old September 23rd, 2008, 05:38 AM
Friend of Wrox
 
Join Date: Jun 2008
Posts: 291
Thanks: 9
Thanked 29 Times in 29 Posts
Default

<xsl:variable name="NotaValue">
        <xsl:apply-templates select="$repoSection//Figure" mode="Notation">
            <xsl:sort select="substring-after(unparsed-entity-uri(@entity), '.')"/>
        </xsl:apply-templates>
        <xsl:apply-templates select="$implSubTree//Figure" mode="Notation">
            <xsl:sort select="substring-after(unparsed-entity-uri(@entity), '.')"/>
        </xsl:apply-templates>
    </xsl:variable>

The above variable gives the value "dib,cgm,gif,cgm,jpeg,". I should sort this text. Is there any way?

 
Old September 23rd, 2008, 05:49 AM
Friend of Wrox
 
Join Date: Nov 2007
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 Posts
Default

Use
Code:
<xsl:variable name="sortedNotaValue" as="xs:string*">
  <xsl:perform-sort select="tokenize($NotaValue, ',')">
    <xsl:sort select="."/>
  </xsl:perform-sort>
</xsl:variable>
--
  Martin Honnen
  Microsoft MVP - XML
 
Old September 23rd, 2008, 06:01 AM
Friend of Wrox
 
Join Date: Jun 2008
Posts: 291
Thanks: 9
Thanked 29 Times in 29 Posts
Default

Thanks Martin. I missed tokenize(), when I was trying.

 
Old September 23rd, 2008, 06:11 AM
Friend of Wrox
 
Join Date: Nov 2007
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 Posts
Default

Depending on your data and your requirements it might suffice to change your original code to
Code:
<xsl:variable name="NotaValue">
        <xsl:apply-templates select="$repoSection//Figure | $implSubTree//Figure" mode="Notation">
            <xsl:sort select="substring-after(unparsed-entity-uri(@entity), '.')"/>
        </xsl:apply-templates>
</xsl:variable>
That way you might not need the second sorting step at all.

--
  Martin Honnen
  Microsoft MVP - XML
 
Old September 23rd, 2008, 06:17 AM
Friend of Wrox
 
Join Date: Jun 2008
Posts: 291
Thanks: 9
Thanked 29 Times in 29 Posts
Default

Thanks a lot Martin






Similar Threads
Thread Thread Starter Forum Replies Last Post
Dynamic sort order or sort datatype kapy_kal XSLT 2 September 18th, 2007 02:10 PM
how to sort cross tab.sort based on row total joxa83 Crystal Reports 7 March 2nd, 2006 09:12 AM
How to call javascript function from VB function vinod_yadav1919 VB How-To 0 February 13th, 2006 06:03 AM
Unable to sort using xsl sort command sly_jimmy_boy XSLT 3 June 17th, 2005 05:15 AM
retreive function/Line from macro or function? MikoMax J2EE 0 April 1st, 2004 04:42 AM





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