Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XML
|
XML General XML discussions.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XML 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 April 18th, 2006, 09:02 AM
Authorized User
 
Join Date: Apr 2006
Posts: 51
Thanks: 0
Thanked 0 Times in 0 Posts
Default order XML file alphabetically

hi all,
I need help organizing my xml file (depending on <title tag) alphabetically. here is a sample of the XML file.
<article artclid="1"><title><titltxt>Adwa, Battle of</titltxt></title><def>definition of term</def></article>
<article artclid="8"><title><titltxt>Malagasy peoples</titltxt></title><def>definition of term</def></article>
<article artclid="3"><title><titltxt>Draco</titltxt></title><def>definition of term</def></article>
<article artclid="10" ><title><titltxt>Red River of the North</titltxt></title><def>definition of term</def></article>
<article artclid="19" ><title><titltxt>Harold I</titltxt></title><def>definition of term</def></article>

 
Old April 18th, 2006, 09:27 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

Assuming the <article> elements are within an <articles> wrapper element, you can do this in XSLT with the rule:

<xsl:template match="articles">
  <xsl:for-each select="article">
    <xsl:sort select="title"/>
    <xsl:copy-of select="."/>
  </xsl:for-each>
</xsl:template>

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old April 18th, 2006, 01:45 PM
Authorized User
 
Join Date: Apr 2006
Posts: 51
Thanks: 0
Thanked 0 Times in 0 Posts
Default

this works fine till I run into words with referenced entities.
example, <titltxt>&Omacr;kubo Toshimichi</titltxt>.

any suggestions?

thanks


bill






Similar Threads
Thread Thread Starter Forum Replies Last Post
Page 77 - Not sorted alphabetically alexlenner BOOK: Beginning PHP, Apache, MySQL Web Development ISBN: 978-0-7645-5744-6 0 August 22nd, 2007 07:36 AM
Getting fields, specific order from xml using xslt Jaipal XSLT 4 July 23rd, 2007 11:35 AM
writing text file but in an order specifed... stone XSLT 2 October 27th, 2005 05:17 AM
alphabetically sort drop down menu crmpicco Javascript How-To 0 August 2nd, 2005 05:03 AM
sorting a column alphabetically Adam H-W SQL Server 2000 8 November 11th, 2003 09:29 AM





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