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

Sort/Ordering Problems

Subject: Sort/Ordering Problems
From: "Benjamin Richard Woline" <valjean@xxxxxxxxxxx>
Date: Wed, 20 Jul 2005 11:35:34 -0500 (CDT)
sorting by name in c
I am having difficulty maintaining the hierarchy in my XML when I try and
reorder/sort the levels.  I am convinced it is issues with both my XPath and my
inexperience with XSLT.  Please advise.


My XML looks like:

<Entry>
<Entry name="A" importance="2">
  <Entry name="B" importance="2">
    <Entry name="C" importance="1"></Entry>
    <Entry name="D" importance="2"></Entry>
  </Entry>
  <Entry name="E" importance="1">
    <Entry name="F" importance="2"></Entry>
    <Entry name="G" importance="1"></Entry>
  </Entry>
</Entry>
<Entry name="H" importance="1">
  <Entry name="I" importance="1">
    <Entry name="J" importance="1"></Entry>
    <Entry name="K" importance="2"></Entry>
  </Entry>
  <Entry name="L" importance="2">
    <Entry name="M" importance="2"></Entry>
    <Entry name="N" importance="1"></Entry>
  </Entry>
</Entry>
</Entry>


I want to sort by importance with each "level" being sorted individually so that
the XML looks like:

<Entry>
<Entry name="H" importance="1">
  <Entry name="I" importance="1">
    <Entry name="J" importance="1"></Entry>
    <Entry name="K" importance="2"></Entry>
  </Entry>
  <Entry name="L" importance="2">
    <Entry name="N" importance="1"></Entry>
    <Entry name="M" importance="2"></Entry>
  </Entry>
</Entry>
<Entry name="A" importance="2">
  <Entry name="E" importance="1">
    <Entry name="G" importance="1"></Entry>
    <Entry name="F" importance="2"></Entry>
  </Entry>
  <Entry name="B" importance="2">
    <Entry name="C" importance="1"></Entry>
    <Entry name="D" importance="2"></Entry>
  </Entry>
</Entry>
</Entry>


When I run this XSLT I get:

<Entry version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:for-each select="//Entry">
	<xsl:sort select="@importance" data-type="number" order="ascending"/>
	<Entry name="{@name}" importance="{@importance}"/>
</xsl:for-each>
</Entry>

<Entry version="1.0">
<Entry name="" importance=""/>
<Entry name="C" importance="1"/>
<Entry name="E" importance="1"/>
<Entry name="G" importance="1"/>
<Entry name="H" importance="1"/>
<Entry name="I" importance="1"/>
<Entry name="J" importance="1"/>
<Entry name="N" importance="1"/>
<Entry name="A" importance="2"/>
<Entry name="B" importance="2"/>
<Entry name="D" importance="2"/>
<Entry name="F" importance="2"/>
<Entry name="K" importance="2"/>
<Entry name="L" importance="2"/>
<Entry name="M" importance="2"/>
</Entry>

I understand the XPath entry is wrong, and I haven't found a differnt path that
gives me the output I want.  That more than likely means I have a problem with
my XSLT initially and no matter what path I insert it will be bad.  Hope someone
can help.

Ben Woline

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.