 |
| 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
|
|
|
|

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

September 23rd, 2008, 04:42 AM
|
|
Friend of Wrox
|
|
Join Date: Nov 2007
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 Posts
|
|
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
|
|

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

September 23rd, 2008, 05:01 AM
|
|
Friend of Wrox
|
|
Join Date: Nov 2007
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 Posts
|
|
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
|
|

September 23rd, 2008, 05:38 AM
|
|
Friend of Wrox
|
|
Join Date: Jun 2008
Posts: 291
Thanks: 9
Thanked 29 Times in 29 Posts
|
|
<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?
|
|

September 23rd, 2008, 05:49 AM
|
|
Friend of Wrox
|
|
Join Date: Nov 2007
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 Posts
|
|
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
|
|

September 23rd, 2008, 06:01 AM
|
|
Friend of Wrox
|
|
Join Date: Jun 2008
Posts: 291
Thanks: 9
Thanked 29 Times in 29 Posts
|
|
Thanks Martin. I missed tokenize(), when I was trying.
|
|

September 23rd, 2008, 06:11 AM
|
|
Friend of Wrox
|
|
Join Date: Nov 2007
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 Posts
|
|
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
|
|

September 23rd, 2008, 06:17 AM
|
|
Friend of Wrox
|
|
Join Date: Jun 2008
Posts: 291
Thanks: 9
Thanked 29 Times in 29 Posts
|
|
Thanks a lot Martin
|
|
 |