[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Is it possible to sort the way I want

Subject: Is it possible to sort the way I want
From: Ian Lang <ianplang@xxxxxxxxx>
Date: Thu, 8 Apr 2004 22:58:25 -0700 (PDT)
flat to hierarchical table xsl
I am building a flat table from the contents of a
hierarchical XML tree.  I want to sort on the fully
qualified name of the element but the data does not
have a qname attribute.  Is it possible?

For example the data might look like this (a
representation of Java code perhaps):
<package name="serviceb">
  <package name="subpackageofb">
  </pacakge>
  <package name="anothersubpackagetofb">
  </pacakge>
</pacakge>
<package name="servicea">
  <package name="subpackageofa">
    <package name="subsubpackageofa">
    </pacakge>
  </pacakge>
  <package name="anothersubpacakgeofa">
  </pacakge>
</pacakge>
<package name="servicec">
</pacakge>

and I want the flat list to look like this:
serviceA
serviceA.anothersubpackageofa
serviceA.subpackageofa
serviceA.subpackageofa.subsubpackageofa
serviceB
serivceB.anothersubpackageofa
serviceB.subpackageofa
serivceC

when I process this using:
<xsl:for-each select="//package">
  <xsl:sort select="@name"/>
    stuff to build the table...

I get this as my order
serviceA
serviceB
serivceC
serivceB.anothersubpackageofa
serviceA.anothersubpackageofa
serviceA.subpackageofa.subsubpackageofa
serviceB.subpackageofa
serviceA.subpackageofa

which is as expected since it is sorting on just the
name of the package.

I also tried this:
<xsl:for-each select="//package">
  <xsl:sort select="ancestor-or-self::*/@name"/>
but that seemed to give me document order or at least
not what I want.

Can this be done directly?  Can I derive the fully
qualified name using XPath for use in the select of
the sort element?  I have a template that outputs the
fully qualified name but it will not 'fit' in a select
statement.  Or am I forced to insert the qualified
name into the XML?

Any advice would be appricated.

Thanks,

IL

__________________________________
Do you Yahoo!?
Yahoo! Small Business $15K Web Design Giveaway 
http://promotions.yahoo.com/design_giveaway/

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.